[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:
parent
2eecc96a53
commit
1bc33d2211
|
@ -1259,7 +1259,42 @@ public class FieldUtilsTest {
|
||||||
assertFalse(field.isAccessible());
|
assertFalse(field.isAccessible());
|
||||||
assertTrue(Modifier.isFinal(field.getModifiers()));
|
assertTrue(Modifier.isFinal(field.getModifiers()));
|
||||||
FieldUtils.removeFinalModifier(field);
|
FieldUtils.removeFinalModifier(field);
|
||||||
|
// The field is no longer final
|
||||||
assertFalse(Modifier.isFinal(field.getModifiers()));
|
assertFalse(Modifier.isFinal(field.getModifiers()));
|
||||||
assertFalse(field.isAccessible());
|
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());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue