From 20fdb8e63eeb511e04e9b5b8ae9cf43a54e4e3f0 Mon Sep 17 00:00:00 2001 From: Rob Tompkins Date: Wed, 10 Apr 2019 14:01:00 -0400 Subject: [PATCH 1/4] jacoco: 0.8.2 -> 0.8.3, surefire: 2.22.1 -> 3.0.0-M3 --- pom.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 2d0b89255..5ceb75c2e 100644 --- a/pom.xml +++ b/pom.xml @@ -606,7 +606,8 @@ 1.21 benchmarks - 0.8.2 + 0.8.3 + 3.0.0-M3 false From 5f7812ee1c2f583e1a1902c96b5b519e86699250 Mon Sep 17 00:00:00 2001 From: Tompkins Date: Wed, 10 Apr 2019 14:46:12 -0400 Subject: [PATCH 2/4] LANG-1447: java 12 final modifier is no longer mutable --- src/changes/changes.xml | 2 + .../commons/lang3/reflect/FieldUtils.java | 13 +++- .../commons/lang3/reflect/FieldUtilsTest.java | 59 ++++++++++++++----- 3 files changed, 57 insertions(+), 17 deletions(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 6138bd410..4668d5b73 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -46,6 +46,8 @@ The type attribute can be add,update,fix,remove. + FieldUtils.removeFinalModifier(Field, boolean), in java 12 + throw exception because the final modifier is no longer mutable. Switch coverage from cobertura to jacoco. Javadoc pointing to Commons RNG. Add more SystemUtils.IS_JAVA_XX variants. 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 68146b165..99148a810 100644 --- a/src/main/java/org/apache/commons/lang3/reflect/FieldUtils.java +++ b/src/main/java/org/apache/commons/lang3/reflect/FieldUtils.java @@ -18,6 +18,7 @@ package org.apache.commons.lang3.reflect; import org.apache.commons.lang3.ClassUtils; import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.SystemUtils; import org.apache.commons.lang3.Validate; import java.lang.annotation.Annotation; @@ -712,8 +713,12 @@ public class FieldUtils { * match {@code public} fields. * @throws IllegalArgumentException * if the field is {@code null} + * @deprecated As of java 12.0, we can no longer drop the final modifier, thus + * rendering this method obsolete. The JDK discussion about this change can be found + * here: http://mail.openjdk.java.net/pipermail/core-libs-dev/2018-November/056486.html * @since 3.3 */ + @Deprecated public static void removeFinalModifier(final Field field, final boolean forceAccess) { Validate.isTrue(field != null, "The field must not be null"); @@ -734,7 +739,13 @@ public class FieldUtils { } } } catch (final NoSuchFieldException | IllegalAccessException ignored) { - // The field class contains always a modifiers field + if (SystemUtils.IS_JAVA_12 || SystemUtils.IS_JAVA_13) { + throw new UnsupportedOperationException( + "In java 12+ final cannot be removed.", + ignored + ); + } + // else no exception is thrown because we can modify final. } } 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 8217a8992..839e89de9 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.SystemUtils; import org.apache.commons.lang3.reflect.testbed.Ambig; import org.apache.commons.lang3.reflect.testbed.Annotated; import org.apache.commons.lang3.reflect.testbed.Foo; @@ -43,6 +44,7 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import static org.junit.jupiter.api.Assumptions.assumeTrue; /** @@ -993,10 +995,11 @@ public class FieldUtilsTest { final Field field = StaticContainer.class.getDeclaredField("IMMUTABLE_PRIVATE_2"); 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()); + callRemoveFinalModifierCheckForException(field, true); + if (!SystemUtils.IS_JAVA_12 && !SystemUtils.IS_JAVA_13) { + assertFalse(Modifier.isFinal(field.getModifiers())); + assertFalse(field.isAccessible()); + } } @Test @@ -1004,10 +1007,11 @@ public class FieldUtilsTest { final 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()); + callRemoveFinalModifierCheckForException(field, true); + if (!SystemUtils.IS_JAVA_12 && !SystemUtils.IS_JAVA_13) { + assertFalse(Modifier.isFinal(field.getModifiers())); + assertFalse(field.isAccessible()); + } } @Test @@ -1015,10 +1019,11 @@ public class FieldUtilsTest { final 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()); + callRemoveFinalModifierCheckForException(field, false); + if (!SystemUtils.IS_JAVA_12 && !SystemUtils.IS_JAVA_13) { + assertTrue(Modifier.isFinal(field.getModifiers())); + assertFalse(field.isAccessible()); + } } @Test @@ -1026,10 +1031,32 @@ public class FieldUtilsTest { final 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()); + callRemoveFinalModifierCheckForException(field, false); + if (!SystemUtils.IS_JAVA_12 && !SystemUtils.IS_JAVA_13) { + assertTrue(Modifier.isFinal(field.getModifiers())); + assertFalse(field.isAccessible()); + } + } + + /** + * Read the @deprecated notice on + * {@link FieldUtils#removeFinalModifier(Field, boolean)}. + * + * @param field {@link Field} to be curried into + * {@link FieldUtils#removeFinalModifier(Field, boolean)}. + * @param forceAccess {@link Boolean} to be curried into + * {@link FieldUtils#removeFinalModifier(Field, boolean)}. + */ + private void callRemoveFinalModifierCheckForException(Field field, Boolean forceAccess) { + try { + FieldUtils.removeFinalModifier(field, forceAccess); + } catch (UnsupportedOperationException exception) { + if(SystemUtils.IS_JAVA_12 || SystemUtils.IS_JAVA_13) { + assertTrue(exception.getCause() instanceof NoSuchFieldException); + } else { + fail("No exception should be thrown for java prior to 12.0"); + } + } } } From f4c0ce3debf01195fbc4f304dfd7a0974ec4ab05 Mon Sep 17 00:00:00 2001 From: Tompkins Date: Wed, 10 Apr 2019 14:46:58 -0400 Subject: [PATCH 3/4] (update) don't allow travis to fail on java 12 --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 4472d838d..8e71802d9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -24,7 +24,6 @@ jdk: matrix: allow_failures: - - jdk: openjdk12 - jdk: openjdk-ea script: From 5b0d49b81393c524727f9195eecbfe7610fc1f6a Mon Sep 17 00:00:00 2001 From: Tompkins Date: Wed, 10 Apr 2019 14:59:59 -0400 Subject: [PATCH 4/4] 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");