[LANG-961] org.apache.commons.lang3.reflect.FieldUtils.removeFinalModifier(Field) does not clean up after itself.

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@1562994 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Gary D. Gregory 2014-01-30 22:00:42 +00:00
parent 2eecc96a53
commit 1bc33d2211
1 changed files with 35 additions and 0 deletions

View File

@ -1259,7 +1259,42 @@ public class FieldUtilsTest {
assertFalse(field.isAccessible());
assertTrue(Modifier.isFinal(field.getModifiers()));
FieldUtils.removeFinalModifier(field);
// The field is no longer final
assertFalse(Modifier.isFinal(field.getModifiers()));
assertFalse(field.isAccessible());
}
@Test
public void testRemoveFinalModifierWithAccess() throws Exception {
Field field = StaticContainer.class.getDeclaredField("IMMUTABLE_PRIVATE_2");
assertFalse(field.isAccessible());
assertTrue(Modifier.isFinal(field.getModifiers()));
FieldUtils.removeFinalModifier(field, true);
// The field is no longer final
assertFalse(Modifier.isFinal(field.getModifiers()));
assertFalse(field.isAccessible());
}
@Test
public void testRemoveFinalModifierWithoutAccess() throws Exception {
Field field = StaticContainer.class.getDeclaredField("IMMUTABLE_PRIVATE_2");
assertFalse(field.isAccessible());
assertTrue(Modifier.isFinal(field.getModifiers()));
FieldUtils.removeFinalModifier(field, false);
// The field is STILL final because we did not force access
assertTrue(Modifier.isFinal(field.getModifiers()));
assertFalse(field.isAccessible());
}
@Test
public void testRemoveFinalModifierAccessNotNeeded() throws Exception {
Field field = StaticContainer.class.getDeclaredField("IMMUTABLE_PACKAGE");
assertFalse(field.isAccessible());
assertTrue(Modifier.isFinal(field.getModifiers()));
FieldUtils.removeFinalModifier(field, false);
// The field is no longer final AND we did not need to force access
assertTrue(Modifier.isFinal(field.getModifiers()));
assertFalse(field.isAccessible());
}
}