Skip to content

Commit 8a1acee

Browse files
committed
Merge branch '3.4.x' into 3.5.x
Closes gh-47620
2 parents a4f49bb + 5ca6771 commit 8a1acee

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/system/JavaVersion.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import java.io.Console;
2020
import java.io.Reader;
21+
import java.lang.reflect.Method;
2122
import java.text.NumberFormat;
2223
import java.time.Duration;
2324
import java.util.Arrays;
@@ -26,6 +27,9 @@
2627
import java.util.SortedSet;
2728
import java.util.concurrent.Future;
2829

30+
import org.springframework.aot.hint.ExecutableMode;
31+
import org.springframework.aot.hint.RuntimeHints;
32+
import org.springframework.aot.hint.RuntimeHintsRegistrar;
2933
import org.springframework.util.ClassUtils;
3034

3135
/**
@@ -96,8 +100,17 @@ public enum JavaVersion {
96100

97101
private final boolean available;
98102

103+
private final Class<?> versionSpecificClass;
104+
105+
private final String versionSpecificMethod;
106+
107+
private final Class<?>[] paramTypes;
108+
99109
JavaVersion(String name, Class<?> versionSpecificClass, String versionSpecificMethod, Class<?>... paramTypes) {
100110
this.name = name;
111+
this.versionSpecificClass = versionSpecificClass;
112+
this.versionSpecificMethod = versionSpecificMethod;
113+
this.paramTypes = paramTypes;
101114
this.available = ClassUtils.hasMethod(versionSpecificClass, versionSpecificMethod, paramTypes);
102115
}
103116

@@ -139,4 +152,28 @@ public boolean isOlderThan(JavaVersion version) {
139152
return compareTo(version) < 0;
140153
}
141154

155+
static class Hints implements RuntimeHintsRegistrar {
156+
157+
@Override
158+
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
159+
for (JavaVersion javaVersion : JavaVersion.values()) {
160+
Method method = findMethod(javaVersion);
161+
if (method != null) {
162+
hints.reflection().registerMethod(method, ExecutableMode.INTROSPECT);
163+
}
164+
}
165+
}
166+
167+
private Method findMethod(JavaVersion javaVersion) {
168+
try {
169+
return ClassUtils.getMethod(javaVersion.versionSpecificClass, javaVersion.versionSpecificMethod,
170+
javaVersion.paramTypes);
171+
}
172+
catch (IllegalStateException ex) {
173+
return null;
174+
}
175+
}
176+
177+
}
178+
142179
}

spring-boot-project/spring-boot/src/main/resources/META-INF/spring/aot.factories

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ org.springframework.boot.logging.logback.LogbackRuntimeHints,\
1313
org.springframework.boot.logging.structured.ElasticCommonSchemaProperties$ElasticCommonSchemaPropertiesRuntimeHints,\
1414
org.springframework.boot.logging.structured.GraylogExtendedLogFormatProperties$GraylogExtendedLogFormatPropertiesRuntimeHints,\
1515
org.springframework.boot.logging.structured.StructuredLoggingJsonProperties$StructuredLoggingJsonPropertiesRuntimeHints,\
16+
org.springframework.boot.system.JavaVersion$Hints,\
1617
org.springframework.boot.web.embedded.undertow.UndertowWebServer$UndertowWebServerRuntimeHints,\
1718
org.springframework.boot.web.server.MimeMappings$MimeMappingsRuntimeHints
1819

0 commit comments

Comments
 (0)