diff --git a/src/main/java/org/apache/commons/lang3/JavaVersion.java b/src/main/java/org/apache/commons/lang3/JavaVersion.java index 60258f63a..148c99e8b 100644 --- a/src/main/java/org/apache/commons/lang3/JavaVersion.java +++ b/src/main/java/org/apache/commons/lang3/JavaVersion.java @@ -94,6 +94,13 @@ public enum JavaVersion { */ JAVA_10(10.0f, "10"), + /** + * Java 11 + * + * @since 3.8 + */ + JAVA_11(11.0f, "11"), + /** * The most recent java version. Mainly introduced to avoid to break when a new version of Java is used. */ @@ -180,6 +187,8 @@ public enum JavaVersion { return JAVA_9; } else if ("10".equals(nom)) { return JAVA_10; + } else if ("11".equals(nom)) { + return JAVA_11; } if (nom == null) { return null; diff --git a/src/main/java/org/apache/commons/lang3/SystemUtils.java b/src/main/java/org/apache/commons/lang3/SystemUtils.java index a6d9c2e9a..f91628a4b 100644 --- a/src/main/java/org/apache/commons/lang3/SystemUtils.java +++ b/src/main/java/org/apache/commons/lang3/SystemUtils.java @@ -985,6 +985,18 @@ public class SystemUtils { */ public static final boolean IS_JAVA_10 = getJavaVersionMatches("10"); + /** + *

+ * Is {@code true} if this is Java version 11 (also 11.x versions). + *

+ *

+ * The field will return {@code false} if {@link #JAVA_VERSION} is {@code null}. + *

+ * + * @since 3.8 + */ + public static final boolean IS_JAVA_11 = getJavaVersionMatches("11"); + // Operating system checks // ----------------------------------------------------------------------- // These MUST be declared after those above as they depend on the diff --git a/src/test/java/org/apache/commons/lang3/JavaVersionTest.java b/src/test/java/org/apache/commons/lang3/JavaVersionTest.java index ad285654f..7a6cbe297 100644 --- a/src/test/java/org/apache/commons/lang3/JavaVersionTest.java +++ b/src/test/java/org/apache/commons/lang3/JavaVersionTest.java @@ -56,10 +56,11 @@ public class JavaVersionTest { assertEquals("1.8 failed", JAVA_1_8, get("1.8")); assertEquals("9 failed", JAVA_9, get("9")); assertEquals("10 failed", JAVA_10, get("10")); + assertEquals("11 failed", JavaVersion.JAVA_11, get("11")); assertEquals("1.10 failed", JAVA_RECENT, get("1.10")); // assertNull("2.10 unexpectedly worked", get("2.10")); assertEquals("Wrapper method failed", get("1.5"), getJavaVersion("1.5")); - assertEquals("Unhandled", JAVA_RECENT, get("11")); // LANG-1384 + assertEquals("Unhandled", JAVA_RECENT, get("12")); // LANG-1384 } @Test diff --git a/src/test/java/org/apache/commons/lang3/SystemUtilsTest.java b/src/test/java/org/apache/commons/lang3/SystemUtilsTest.java index b97cb8113..8e5610cf4 100644 --- a/src/test/java/org/apache/commons/lang3/SystemUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/SystemUtilsTest.java @@ -29,6 +29,7 @@ import static org.apache.commons.lang3.JavaVersion.JAVA_1_7; import static org.apache.commons.lang3.JavaVersion.JAVA_1_8; import static org.apache.commons.lang3.JavaVersion.JAVA_9; import static org.apache.commons.lang3.JavaVersion.JAVA_10; +import static org.apache.commons.lang3.JavaVersion.JAVA_11; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; @@ -408,6 +409,7 @@ public class SystemUtilsTest { assertFalse(SystemUtils.isJavaVersionAtLeast(JAVA_1_8)); assertFalse(SystemUtils.isJavaVersionAtLeast(JAVA_9)); assertFalse(SystemUtils.isJavaVersionAtLeast(JAVA_10)); + assertFalse(SystemUtils.isJavaVersionAtLeast(JAVA_11)); } else if (SystemUtils.IS_JAVA_1_8) { assertTrue(SystemUtils.isJavaVersionAtLeast(JAVA_1_1)); assertTrue(SystemUtils.isJavaVersionAtLeast(JAVA_1_2)); @@ -419,6 +421,7 @@ public class SystemUtilsTest { assertTrue(SystemUtils.isJavaVersionAtLeast(JAVA_1_8)); assertFalse(SystemUtils.isJavaVersionAtLeast(JAVA_9)); assertFalse(SystemUtils.isJavaVersionAtLeast(JAVA_10)); + assertFalse(SystemUtils.isJavaVersionAtLeast(JAVA_11)); } else if (SystemUtils.IS_JAVA_9) { assertTrue(SystemUtils.isJavaVersionAtLeast(JAVA_1_1)); assertTrue(SystemUtils.isJavaVersionAtLeast(JAVA_1_2)); @@ -430,6 +433,7 @@ public class SystemUtilsTest { assertTrue(SystemUtils.isJavaVersionAtLeast(JAVA_1_8)); assertTrue(SystemUtils.isJavaVersionAtLeast(JAVA_9)); assertFalse(SystemUtils.isJavaVersionAtLeast(JAVA_10)); + assertFalse(SystemUtils.isJavaVersionAtLeast(JAVA_11)); } else if (SystemUtils.IS_JAVA_10) { assertTrue(SystemUtils.isJavaVersionAtLeast(JAVA_1_1)); assertTrue(SystemUtils.isJavaVersionAtLeast(JAVA_1_2)); @@ -441,6 +445,19 @@ public class SystemUtilsTest { assertTrue(SystemUtils.isJavaVersionAtLeast(JAVA_1_8)); assertTrue(SystemUtils.isJavaVersionAtLeast(JAVA_9)); assertTrue(SystemUtils.isJavaVersionAtLeast(JAVA_10)); + assertFalse(SystemUtils.isJavaVersionAtLeast(JAVA_11)); + } else if (SystemUtils.IS_JAVA_11) { + assertTrue(SystemUtils.isJavaVersionAtLeast(JAVA_1_1)); + assertTrue(SystemUtils.isJavaVersionAtLeast(JAVA_1_2)); + assertTrue(SystemUtils.isJavaVersionAtLeast(JAVA_1_3)); + assertTrue(SystemUtils.isJavaVersionAtLeast(JAVA_1_4)); + assertTrue(SystemUtils.isJavaVersionAtLeast(JAVA_1_5)); + assertTrue(SystemUtils.isJavaVersionAtLeast(JAVA_1_6)); + assertTrue(SystemUtils.isJavaVersionAtLeast(JAVA_1_7)); + assertTrue(SystemUtils.isJavaVersionAtLeast(JAVA_1_8)); + assertTrue(SystemUtils.isJavaVersionAtLeast(JAVA_9)); + assertTrue(SystemUtils.isJavaVersionAtLeast(JAVA_10)); + assertTrue(SystemUtils.isJavaVersionAtLeast(JAVA_11)); } }