[LANG-1365] Fix NullPointerException in isJavaVersionAtLeast on Java 10,
add SystemUtils.IS_JAVA_10, add JavaVersion.JAVA_10.
This commit is contained in:
parent
a26c66a8ed
commit
a618b844c5
|
@ -45,7 +45,8 @@ The <action> type attribute can be add,update,fix,remove.
|
|||
</properties>
|
||||
<body>
|
||||
|
||||
<release version="3.7" date="2017-MM-DD" description="New features and bug fixes. Requires Java 7.">
|
||||
<release version="3.7" date="2017-MM-DD" description="New features and bug fixes. Requires Java 7, supports Java 8, 9, 10.">
|
||||
<action issue="LANG-1365" type="fix" dev="ggregory" due-to="Gary Gregory">Fix NullPointerException in isJavaVersionAtLeast on Java 10, add SystemUtils.IS_JAVA_10, add JavaVersion.JAVA_10</action>
|
||||
<action issue="LANG-1358" type="update" dev="pschumacher" due-to="Stephane Landelle">Improve StringUtils#replace throughput</action>
|
||||
<action issue="LANG-1355" type="add" dev="ggregory" due-to="Chas Honton">TimeZone.getTimeZone() in FastDateParser causes resource contention (PR #296.)</action>
|
||||
<action issue="LANG-1348" type="fix" dev="pschumacher" due-to="mbusso">StackOverflowError on TypeUtils.toString(...) for a generic return type of Enum.valueOf</action>
|
||||
|
|
|
@ -82,9 +82,18 @@ public enum JavaVersion {
|
|||
|
||||
/**
|
||||
* Java 9
|
||||
*
|
||||
* @since 3.5
|
||||
*/
|
||||
JAVA_9(9.0f, "9"),
|
||||
|
||||
/**
|
||||
* Java 10
|
||||
*
|
||||
* @since 3.7
|
||||
*/
|
||||
JAVA_10(10.0f, "10"),
|
||||
|
||||
/**
|
||||
* The most recent java version. Mainly introduced to avoid to break when a new version of Java is used.
|
||||
*/
|
||||
|
@ -168,6 +177,8 @@ public enum JavaVersion {
|
|||
return JAVA_1_8;
|
||||
} else if ("9".equals(nom)) {
|
||||
return JAVA_9;
|
||||
} else if ("10".equals(nom)) {
|
||||
return JAVA_10;
|
||||
}
|
||||
if (nom == null) {
|
||||
return null;
|
||||
|
|
|
@ -973,6 +973,18 @@ public class SystemUtils {
|
|||
*/
|
||||
public static final boolean IS_JAVA_9 = getJavaVersionMatches("9");
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Is {@code true} if this is Java version 10 (also 10.x versions).
|
||||
* </p>
|
||||
* <p>
|
||||
* The field will return {@code false} if {@link #JAVA_VERSION} is {@code null}.
|
||||
* </p>
|
||||
*
|
||||
* @since 3.7
|
||||
*/
|
||||
public static final boolean IS_JAVA_10 = getJavaVersionMatches("10");
|
||||
|
||||
// Operating system checks
|
||||
// -----------------------------------------------------------------------
|
||||
// These MUST be declared after those above as they depend on the
|
||||
|
|
|
@ -34,6 +34,7 @@ import static org.apache.commons.lang3.JavaVersion.JAVA_1_6;
|
|||
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.get;
|
||||
import static org.apache.commons.lang3.JavaVersion.getJavaVersion;
|
||||
|
||||
|
@ -54,6 +55,7 @@ public class JavaVersionTest {
|
|||
assertEquals("1.7 failed", JAVA_1_7, get("1.7"));
|
||||
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("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"));
|
||||
|
|
|
@ -28,6 +28,7 @@ import static org.apache.commons.lang3.JavaVersion.JAVA_1_6;
|
|||
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.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
@ -119,6 +120,7 @@ public class SystemUtilsTest {
|
|||
assertFalse(SystemUtils.IS_JAVA_1_8);
|
||||
assertFalse(SystemUtils.IS_JAVA_1_9);
|
||||
assertFalse(SystemUtils.IS_JAVA_9);
|
||||
assertFalse(SystemUtils.IS_JAVA_10);
|
||||
} else if (javaVersion.startsWith("1.7")) {
|
||||
assertFalse(SystemUtils.IS_JAVA_1_1);
|
||||
assertFalse(SystemUtils.IS_JAVA_1_2);
|
||||
|
@ -130,6 +132,7 @@ public class SystemUtilsTest {
|
|||
assertFalse(SystemUtils.IS_JAVA_1_8);
|
||||
assertFalse(SystemUtils.IS_JAVA_1_9);
|
||||
assertFalse(SystemUtils.IS_JAVA_9);
|
||||
assertFalse(SystemUtils.IS_JAVA_10);
|
||||
} else if (javaVersion.startsWith("1.8")) {
|
||||
assertFalse(SystemUtils.IS_JAVA_1_1);
|
||||
assertFalse(SystemUtils.IS_JAVA_1_2);
|
||||
|
@ -141,6 +144,7 @@ public class SystemUtilsTest {
|
|||
assertTrue(SystemUtils.IS_JAVA_1_8);
|
||||
assertFalse(SystemUtils.IS_JAVA_1_9);
|
||||
assertFalse(SystemUtils.IS_JAVA_9);
|
||||
assertFalse(SystemUtils.IS_JAVA_10);
|
||||
} else if (javaVersion.startsWith("9")) {
|
||||
assertFalse(SystemUtils.IS_JAVA_1_1);
|
||||
assertFalse(SystemUtils.IS_JAVA_1_2);
|
||||
|
@ -152,8 +156,21 @@ public class SystemUtilsTest {
|
|||
assertFalse(SystemUtils.IS_JAVA_1_8);
|
||||
assertTrue(SystemUtils.IS_JAVA_1_9);
|
||||
assertTrue(SystemUtils.IS_JAVA_9);
|
||||
assertFalse(SystemUtils.IS_JAVA_10);
|
||||
} else if (javaVersion.startsWith("10")) {
|
||||
assertFalse(SystemUtils.IS_JAVA_1_1);
|
||||
assertFalse(SystemUtils.IS_JAVA_1_2);
|
||||
assertFalse(SystemUtils.IS_JAVA_1_3);
|
||||
assertFalse(SystemUtils.IS_JAVA_1_4);
|
||||
assertFalse(SystemUtils.IS_JAVA_1_5);
|
||||
assertFalse(SystemUtils.IS_JAVA_1_6);
|
||||
assertFalse(SystemUtils.IS_JAVA_1_7);
|
||||
assertFalse(SystemUtils.IS_JAVA_1_8);
|
||||
assertFalse(SystemUtils.IS_JAVA_1_9);
|
||||
assertFalse(SystemUtils.IS_JAVA_9);
|
||||
assertTrue(SystemUtils.IS_JAVA_10);
|
||||
} else {
|
||||
System.out.println("Can't test IS_JAVA value: "+javaVersion);
|
||||
System.out.println("Can't test IS_JAVA value: " + javaVersion);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -390,6 +407,7 @@ public class SystemUtilsTest {
|
|||
assertTrue(SystemUtils.isJavaVersionAtLeast(JAVA_1_7));
|
||||
assertFalse(SystemUtils.isJavaVersionAtLeast(JAVA_1_8));
|
||||
assertFalse(SystemUtils.isJavaVersionAtLeast(JAVA_9));
|
||||
assertFalse(SystemUtils.isJavaVersionAtLeast(JAVA_10));
|
||||
} else if (SystemUtils.IS_JAVA_1_8) {
|
||||
assertTrue(SystemUtils.isJavaVersionAtLeast(JAVA_1_1));
|
||||
assertTrue(SystemUtils.isJavaVersionAtLeast(JAVA_1_2));
|
||||
|
@ -400,6 +418,7 @@ public class SystemUtilsTest {
|
|||
assertTrue(SystemUtils.isJavaVersionAtLeast(JAVA_1_7));
|
||||
assertTrue(SystemUtils.isJavaVersionAtLeast(JAVA_1_8));
|
||||
assertFalse(SystemUtils.isJavaVersionAtLeast(JAVA_9));
|
||||
assertFalse(SystemUtils.isJavaVersionAtLeast(JAVA_10));
|
||||
} else if (SystemUtils.IS_JAVA_9) {
|
||||
assertTrue(SystemUtils.isJavaVersionAtLeast(JAVA_1_1));
|
||||
assertTrue(SystemUtils.isJavaVersionAtLeast(JAVA_1_2));
|
||||
|
@ -410,6 +429,18 @@ public class SystemUtilsTest {
|
|||
assertTrue(SystemUtils.isJavaVersionAtLeast(JAVA_1_7));
|
||||
assertTrue(SystemUtils.isJavaVersionAtLeast(JAVA_1_8));
|
||||
assertTrue(SystemUtils.isJavaVersionAtLeast(JAVA_9));
|
||||
assertFalse(SystemUtils.isJavaVersionAtLeast(JAVA_10));
|
||||
} else if (SystemUtils.IS_JAVA_10) {
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue