LANG-1447: use isJavaVersionAtLeast in implementation

This commit is contained in:
Tompkins 2019-04-10 14:59:59 -04:00
parent f4c0ce3deb
commit 5b0d49b813
2 changed files with 8 additions and 6 deletions

View File

@ -17,6 +17,7 @@
package org.apache.commons.lang3.reflect;
import org.apache.commons.lang3.ClassUtils;
import org.apache.commons.lang3.JavaVersion;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.SystemUtils;
import org.apache.commons.lang3.Validate;
@ -739,7 +740,7 @@ public class FieldUtils {
}
}
} catch (final NoSuchFieldException | IllegalAccessException ignored) {
if (SystemUtils.IS_JAVA_12 || SystemUtils.IS_JAVA_13) {
if (SystemUtils.isJavaVersionAtLeast(JavaVersion.JAVA_12)) {
throw new UnsupportedOperationException(
"In java 12+ final cannot be removed.",
ignored

View File

@ -18,6 +18,7 @@ package org.apache.commons.lang3.reflect;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.JavaVersion;
import org.apache.commons.lang3.SystemUtils;
import org.apache.commons.lang3.reflect.testbed.Ambig;
import org.apache.commons.lang3.reflect.testbed.Annotated;
@ -996,7 +997,7 @@ public class FieldUtilsTest {
assertFalse(field.isAccessible());
assertTrue(Modifier.isFinal(field.getModifiers()));
callRemoveFinalModifierCheckForException(field, true);
if (!SystemUtils.IS_JAVA_12 && !SystemUtils.IS_JAVA_13) {
if (SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_11)) {
assertFalse(Modifier.isFinal(field.getModifiers()));
assertFalse(field.isAccessible());
}
@ -1008,7 +1009,7 @@ public class FieldUtilsTest {
assertFalse(field.isAccessible());
assertTrue(Modifier.isFinal(field.getModifiers()));
callRemoveFinalModifierCheckForException(field, true);
if (!SystemUtils.IS_JAVA_12 && !SystemUtils.IS_JAVA_13) {
if (SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_11)) {
assertFalse(Modifier.isFinal(field.getModifiers()));
assertFalse(field.isAccessible());
}
@ -1020,7 +1021,7 @@ public class FieldUtilsTest {
assertFalse(field.isAccessible());
assertTrue(Modifier.isFinal(field.getModifiers()));
callRemoveFinalModifierCheckForException(field, false);
if (!SystemUtils.IS_JAVA_12 && !SystemUtils.IS_JAVA_13) {
if (SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_11)) {
assertTrue(Modifier.isFinal(field.getModifiers()));
assertFalse(field.isAccessible());
}
@ -1032,7 +1033,7 @@ public class FieldUtilsTest {
assertFalse(field.isAccessible());
assertTrue(Modifier.isFinal(field.getModifiers()));
callRemoveFinalModifierCheckForException(field, false);
if (!SystemUtils.IS_JAVA_12 && !SystemUtils.IS_JAVA_13) {
if (SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_11)) {
assertTrue(Modifier.isFinal(field.getModifiers()));
assertFalse(field.isAccessible());
}
@ -1051,7 +1052,7 @@ public class FieldUtilsTest {
try {
FieldUtils.removeFinalModifier(field, forceAccess);
} catch (UnsupportedOperationException exception) {
if(SystemUtils.IS_JAVA_12 || SystemUtils.IS_JAVA_13) {
if(SystemUtils.isJavaVersionAtLeast(JavaVersion.JAVA_12)) {
assertTrue(exception.getCause() instanceof NoSuchFieldException);
} else {
fail("No exception should be thrown for java prior to 12.0");