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 773c8d7bd9..6eafbf0d6d 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 @@ -1,5 +1,5 @@ /* - * Copyright 2012-2022 the original author or authors. + * Copyright 2012-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,6 +33,7 @@ import org.springframework.util.ClassUtils; * * @author Oliver Gierke * @author Phillip Webb + * @author Moritz Halbritter * @since 2.0.0 */ public enum JavaVersion { @@ -95,7 +96,12 @@ public enum JavaVersion { /** * Java 19. */ - NINETEEN("19", Future.class, "state"); + NINETEEN("19", Future.class, "state"), + + /** + * Java 20. + */ + TWENTY("20", Class.class, "accessFlags"); 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 2cf29cc4cd..323f342c3c 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 @@ -1,5 +1,5 @@ /* - * Copyright 2012-2022 the original author or authors. + * Copyright 2012-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -152,8 +152,18 @@ class JavaVersionTests { assertThat(JavaVersion.getJavaVersion()).isEqualTo(JavaVersion.NINETEEN); } + @Test + @EnabledIf("java20") + void currentJavaVersionTwenty() { + assertThat(JavaVersion.getJavaVersion()).isEqualTo(JavaVersion.TWENTY); + } + static boolean java19() { return "19".equals(System.getProperty("java.version")); } + static boolean java20() { + return System.getProperty("java.version").startsWith("20"); + } + }