Skip to content

Commit

Permalink
Add SystemUtils.IS_JAVA_23
Browse files Browse the repository at this point in the history
Add JavaVersion.JAVA_23
  • Loading branch information
garydgregory committed Oct 6, 2024
1 parent e3883c0 commit e7437aa
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/changes/changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ The <action> type attribute can be add,update,fix,remove.
<!-- ADD -->
<action type="add" dev="ggregory" due-to="Gary Gregory">Add Strings and refactor StringUtils.</action>
<action issue="LANG-1747" type="add" dev="ggregory" due-to="Oliver B. Fischer, Gary Gregory">Add StopWatch.run([Failable]Runnable) and get([Failable]Supplier).</action>
<action type="add" dev="ggregory" due-to="Gary Gregory">JavaVersion.JAVA_23.</action>
<action type="add" dev="ggregory" due-to="Gary Gregory">SystemUtils.IS_JAVA_23.</action>
<!-- UPDATE -->
<action type="update" dev="ggregory" due-to="Gary Gregory, Dependabot">Bump org.apache.commons:commons-parent from 73 to 76 #1267, #1277, #1283.</action>
</release>
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/org/apache/commons/lang3/JavaVersion.java
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,13 @@ public enum JavaVersion {
*/
JAVA_22(22, "22"),

/**
* Java 23.
*
* @since 3.18.0
*/
JAVA_23(23, "23"),

/**
* The most recent Java version. Mainly introduced to avoid to break when a new version of Java is used.
*/
Expand Down Expand Up @@ -248,6 +255,8 @@ static JavaVersion get(final String versionStr) {
return JAVA_21;
case "22":
return JAVA_22;
case "23":
return JAVA_23;
default:
final float v = toFloatVersion(versionStr);
if (v - 1. < 1.) { // then we need to check decimals > .9
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/org/apache/commons/lang3/SystemUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -1123,6 +1123,19 @@ public class SystemUtils {
*/
public static final boolean IS_JAVA_22 = getJavaVersionMatches("22");

/**
* Is {@code true} if this is Java version 23 (also 23.x versions).
* <p>
* The field will return {@code false} if {@link #JAVA_VERSION} is {@code null}.
* </p>
* <p>
* This value is initialized when the class is loaded.
* </p>
*
* @since 3.18.0
*/
public static final boolean IS_JAVA_23 = getJavaVersionMatches("23");

// Operating system checks
// -----------------------------------------------------------------------
// These MUST be declared after those above as they depend on the
Expand Down
3 changes: 2 additions & 1 deletion src/test/java/org/apache/commons/lang3/JavaVersionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,12 @@ public void testGetJavaVersion() throws Exception {
assertEquals(JavaVersion.JAVA_20, JavaVersion.get("20"));
assertEquals(JavaVersion.JAVA_21, JavaVersion.get("21"));
assertEquals(JavaVersion.JAVA_22, JavaVersion.get("22"));
assertEquals(JavaVersion.JAVA_23, JavaVersion.get("23"));

assertEquals(JavaVersion.JAVA_RECENT, JavaVersion.get("1.10"), "1.10 failed");
// assertNull("2.10 unexpectedly worked", JavaVersion.get("2.10"));
assertEquals(JavaVersion.get("1.5"), JavaVersion.getJavaVersion("1.5"), "Wrapper method failed");
assertEquals(JavaVersion.JAVA_RECENT, JavaVersion.get("23"), "Unhandled"); // LANG-1384
assertEquals(JavaVersion.JAVA_RECENT, JavaVersion.get("24"), "Unhandled"); // LANG-1384
}

@Test
Expand Down
50 changes: 48 additions & 2 deletions src/test/java/org/apache/commons/lang3/SystemUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ public void test_IS_JAVA() throws Exception {
assertFalse(SystemUtils.IS_JAVA_20);
assertFalse(SystemUtils.IS_JAVA_21);
assertFalse(SystemUtils.IS_JAVA_22);
assertFalse(SystemUtils.IS_JAVA_23);
for (int version = 9; version <= lastSupportedVersion; version++) {
assertFalse(getIS_JAVA(version));
}
Expand All @@ -116,7 +117,7 @@ public void test_IS_JAVA() throws Exception {
assertFalse(SystemUtils.IS_JAVA_20);
assertFalse(SystemUtils.IS_JAVA_21);
assertFalse(SystemUtils.IS_JAVA_22);

assertFalse(SystemUtils.IS_JAVA_23);
for (int version = 9; version <= lastSupportedVersion; version++) {
assertFalse(getIS_JAVA(version));
}
Expand Down Expand Up @@ -326,6 +327,7 @@ public void testIsJavaVersionAtLeast() {
assertFalse(SystemUtils.isJavaVersionAtLeast(JavaVersion.JAVA_20));
assertFalse(SystemUtils.isJavaVersionAtLeast(JavaVersion.JAVA_21));
assertFalse(SystemUtils.isJavaVersionAtLeast(JavaVersion.JAVA_22));
assertFalse(SystemUtils.isJavaVersionAtLeast(JavaVersion.JAVA_23));
} else if (SystemUtils.IS_JAVA_9) {
assertTrue(SystemUtils.isJavaVersionAtLeast(JavaVersion.JAVA_1_1));
assertTrue(SystemUtils.isJavaVersionAtLeast(JavaVersion.JAVA_1_2));
Expand All @@ -349,6 +351,7 @@ public void testIsJavaVersionAtLeast() {
assertFalse(SystemUtils.isJavaVersionAtLeast(JavaVersion.JAVA_20));
assertFalse(SystemUtils.isJavaVersionAtLeast(JavaVersion.JAVA_21));
assertFalse(SystemUtils.isJavaVersionAtLeast(JavaVersion.JAVA_22));
assertFalse(SystemUtils.isJavaVersionAtLeast(JavaVersion.JAVA_23));
} else if (SystemUtils.IS_JAVA_10) {
assertTrue(SystemUtils.isJavaVersionAtLeast(JavaVersion.JAVA_1_1));
assertTrue(SystemUtils.isJavaVersionAtLeast(JavaVersion.JAVA_1_2));
Expand All @@ -372,6 +375,7 @@ public void testIsJavaVersionAtLeast() {
assertFalse(SystemUtils.isJavaVersionAtLeast(JavaVersion.JAVA_20));
assertFalse(SystemUtils.isJavaVersionAtLeast(JavaVersion.JAVA_21));
assertFalse(SystemUtils.isJavaVersionAtLeast(JavaVersion.JAVA_22));
assertFalse(SystemUtils.isJavaVersionAtLeast(JavaVersion.JAVA_23));
} else if (SystemUtils.IS_JAVA_11) {
assertTrue(SystemUtils.isJavaVersionAtLeast(JavaVersion.JAVA_1_1));
assertTrue(SystemUtils.isJavaVersionAtLeast(JavaVersion.JAVA_1_2));
Expand All @@ -395,6 +399,7 @@ public void testIsJavaVersionAtLeast() {
assertFalse(SystemUtils.isJavaVersionAtLeast(JavaVersion.JAVA_20));
assertFalse(SystemUtils.isJavaVersionAtLeast(JavaVersion.JAVA_21));
assertFalse(SystemUtils.isJavaVersionAtLeast(JavaVersion.JAVA_22));
assertFalse(SystemUtils.isJavaVersionAtLeast(JavaVersion.JAVA_23));
} else if (SystemUtils.IS_JAVA_12) {
assertTrue(SystemUtils.isJavaVersionAtLeast(JavaVersion.JAVA_1_1));
assertTrue(SystemUtils.isJavaVersionAtLeast(JavaVersion.JAVA_1_2));
Expand All @@ -418,6 +423,7 @@ public void testIsJavaVersionAtLeast() {
assertFalse(SystemUtils.isJavaVersionAtLeast(JavaVersion.JAVA_20));
assertFalse(SystemUtils.isJavaVersionAtLeast(JavaVersion.JAVA_21));
assertFalse(SystemUtils.isJavaVersionAtLeast(JavaVersion.JAVA_22));
assertFalse(SystemUtils.isJavaVersionAtLeast(JavaVersion.JAVA_23));
} else if (SystemUtils.IS_JAVA_13) {
assertTrue(SystemUtils.isJavaVersionAtLeast(JavaVersion.JAVA_1_1));
assertTrue(SystemUtils.isJavaVersionAtLeast(JavaVersion.JAVA_1_2));
Expand All @@ -441,6 +447,7 @@ public void testIsJavaVersionAtLeast() {
assertFalse(SystemUtils.isJavaVersionAtLeast(JavaVersion.JAVA_20));
assertFalse(SystemUtils.isJavaVersionAtLeast(JavaVersion.JAVA_21));
assertFalse(SystemUtils.isJavaVersionAtLeast(JavaVersion.JAVA_22));
assertFalse(SystemUtils.isJavaVersionAtLeast(JavaVersion.JAVA_23));
}
}

Expand Down Expand Up @@ -469,6 +476,7 @@ public void testIsJavaVersionAtMost() {
assertTrue(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_20));
assertTrue(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_21));
assertTrue(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_22));
assertTrue(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_23));
} else if (SystemUtils.IS_JAVA_9) {
assertFalse(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_1_1));
assertFalse(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_1_2));
Expand All @@ -492,6 +500,7 @@ public void testIsJavaVersionAtMost() {
assertTrue(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_20));
assertTrue(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_21));
assertTrue(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_22));
assertTrue(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_23));
} else if (SystemUtils.IS_JAVA_10) {
assertFalse(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_1_1));
assertFalse(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_1_2));
Expand All @@ -515,6 +524,7 @@ public void testIsJavaVersionAtMost() {
assertTrue(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_20));
assertTrue(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_21));
assertTrue(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_22));
assertTrue(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_23));
} else if (SystemUtils.IS_JAVA_11) {
assertFalse(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_1_1));
assertFalse(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_1_2));
Expand All @@ -538,6 +548,7 @@ public void testIsJavaVersionAtMost() {
assertTrue(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_20));
assertTrue(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_21));
assertTrue(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_22));
assertTrue(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_23));
} else if (SystemUtils.IS_JAVA_12) {
assertFalse(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_1_1));
assertFalse(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_1_2));
Expand All @@ -561,6 +572,7 @@ public void testIsJavaVersionAtMost() {
assertTrue(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_20));
assertTrue(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_21));
assertTrue(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_22));
assertTrue(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_23));
} else if (SystemUtils.IS_JAVA_13) {
assertFalse(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_1_1));
assertFalse(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_1_2));
Expand All @@ -584,6 +596,7 @@ public void testIsJavaVersionAtMost() {
assertTrue(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_20));
assertTrue(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_21));
assertTrue(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_22));
assertTrue(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_23));
} else if (SystemUtils.IS_JAVA_14) {
assertFalse(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_1_1));
assertFalse(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_1_2));
Expand All @@ -607,6 +620,7 @@ public void testIsJavaVersionAtMost() {
assertTrue(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_20));
assertTrue(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_21));
assertTrue(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_22));
assertTrue(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_23));
} else if (SystemUtils.IS_JAVA_15) {
assertFalse(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_1_1));
assertFalse(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_1_2));
Expand All @@ -630,6 +644,7 @@ public void testIsJavaVersionAtMost() {
assertTrue(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_20));
assertTrue(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_21));
assertTrue(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_22));
assertTrue(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_23));
} else if (SystemUtils.IS_JAVA_16) {
assertFalse(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_1_1));
assertFalse(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_1_2));
Expand All @@ -653,7 +668,8 @@ public void testIsJavaVersionAtMost() {
assertTrue(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_20));
assertTrue(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_21));
assertTrue(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_22));
} else if (SystemUtils.IS_JAVA_17) {
assertTrue(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_23));
} else if (SystemUtils.IS_JAVA_17) {
assertFalse(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_1_1));
assertFalse(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_1_2));
assertFalse(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_1_3));
Expand All @@ -676,6 +692,7 @@ public void testIsJavaVersionAtMost() {
assertTrue(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_20));
assertTrue(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_21));
assertTrue(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_22));
assertTrue(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_23));
} else if (SystemUtils.IS_JAVA_18) {
assertFalse(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_1_1));
assertFalse(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_1_2));
Expand All @@ -699,6 +716,7 @@ public void testIsJavaVersionAtMost() {
assertTrue(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_20));
assertTrue(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_21));
assertTrue(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_22));
assertTrue(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_23));
} else if (SystemUtils.IS_JAVA_19) {
assertFalse(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_1_1));
assertFalse(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_1_2));
Expand All @@ -722,6 +740,7 @@ public void testIsJavaVersionAtMost() {
assertTrue(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_20));
assertTrue(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_21));
assertTrue(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_22));
assertTrue(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_23));
} else if (SystemUtils.IS_JAVA_20) {
assertFalse(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_1_1));
assertFalse(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_1_2));
Expand All @@ -745,6 +764,7 @@ public void testIsJavaVersionAtMost() {
assertTrue(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_20));
assertTrue(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_21));
assertTrue(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_22));
assertTrue(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_23));
} else if (SystemUtils.IS_JAVA_21) {
assertFalse(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_1_1));
assertFalse(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_1_2));
Expand All @@ -768,6 +788,7 @@ public void testIsJavaVersionAtMost() {
assertFalse(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_20));
assertTrue(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_21));
assertTrue(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_22));
assertTrue(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_23));
} else if (SystemUtils.IS_JAVA_22) {
assertFalse(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_1_1));
assertFalse(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_1_2));
Expand All @@ -791,6 +812,31 @@ public void testIsJavaVersionAtMost() {
assertFalse(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_20));
assertFalse(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_21));
assertTrue(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_22));
assertTrue(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_23));
} else if (SystemUtils.IS_JAVA_23) {
assertFalse(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_1_1));
assertFalse(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_1_2));
assertFalse(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_1_3));
assertFalse(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_1_4));
assertFalse(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_1_5));
assertFalse(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_1_6));
assertFalse(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_1_7));
assertFalse(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_1_8));
assertFalse(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_9));
assertFalse(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_10));
assertFalse(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_11));
assertFalse(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_12));
assertFalse(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_13));
assertFalse(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_14));
assertFalse(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_15));
assertFalse(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_16));
assertFalse(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_17));
assertFalse(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_18));
assertFalse(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_19));
assertFalse(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_20));
assertFalse(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_21));
assertFalse(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_22));
assertTrue(SystemUtils.isJavaVersionAtMost(JavaVersion.JAVA_23));
}
}

Expand Down

0 comments on commit e7437aa

Please sign in to comment.