From 13a3e3bdf021d43c73b369b49afc87ad51d15d05 Mon Sep 17 00:00:00 2001 From: Moritz Halbritter Date: Tue, 6 Jun 2023 09:38:50 +0200 Subject: [PATCH] Add TWENTY_ONE to JavaVersion Closes gh-37362 --- .../org/springframework/boot/system/JavaVersion.java | 9 ++++++++- .../springframework/boot/system/JavaVersionTests.java | 10 ++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/system/JavaVersion.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/system/JavaVersion.java index c5a8cea603..79683f56e3 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/system/JavaVersion.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/system/JavaVersion.java @@ -23,6 +23,7 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Optional; +import java.util.SortedSet; import java.util.concurrent.Future; import java.util.stream.Stream; @@ -114,7 +115,13 @@ public enum JavaVersion { * Java 20. * @since 2.7.13 */ - TWENTY("20", Class.class, "accessFlags"); + TWENTY("20", Class.class, "accessFlags"), + + /** + * Java 21. + * @since 2.7.16 + */ + TWENTY_ONE("21", SortedSet.class, "getFirst"); private final String name; diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/system/JavaVersionTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/system/JavaVersionTests.java index 323f342c3c..21063f0886 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/system/JavaVersionTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/system/JavaVersionTests.java @@ -158,6 +158,12 @@ class JavaVersionTests { assertThat(JavaVersion.getJavaVersion()).isEqualTo(JavaVersion.TWENTY); } + @Test + @EnabledIf("java21") + void currentJavaVersionTwentyOne() { + assertThat(JavaVersion.getJavaVersion()).isEqualTo(JavaVersion.TWENTY_ONE); + } + static boolean java19() { return "19".equals(System.getProperty("java.version")); } @@ -166,4 +172,8 @@ class JavaVersionTests { return System.getProperty("java.version").startsWith("20"); } + static boolean java21() { + return System.getProperty("java.version").startsWith("21"); + } + }