From 5b0d49b81393c524727f9195eecbfe7610fc1f6a Mon Sep 17 00:00:00 2001 From: Tompkins Date: Wed, 10 Apr 2019 14:59:59 -0400 Subject: [PATCH] LANG-1447: use isJavaVersionAtLeast in implementation --- .../org/apache/commons/lang3/reflect/FieldUtils.java | 3 ++- .../apache/commons/lang3/reflect/FieldUtilsTest.java | 11 ++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/apache/commons/lang3/reflect/FieldUtils.java b/src/main/java/org/apache/commons/lang3/reflect/FieldUtils.java index 99148a810..08fcdc2b4 100644 --- a/src/main/java/org/apache/commons/lang3/reflect/FieldUtils.java +++ b/src/main/java/org/apache/commons/lang3/reflect/FieldUtils.java @@ -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 diff --git a/src/test/java/org/apache/commons/lang3/reflect/FieldUtilsTest.java b/src/test/java/org/apache/commons/lang3/reflect/FieldUtilsTest.java index 839e89de9..39239efce 100644 --- a/src/test/java/org/apache/commons/lang3/reflect/FieldUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/reflect/FieldUtilsTest.java @@ -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");