From 44f1949c5eb39e187451e1286a41c1fe4d0e7168 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Thu, 1 Sep 2022 19:43:43 -0700 Subject: [PATCH] Polish hint API calls --- .../CloudFoundryWebEndpointDiscoverer.java | 2 +- .../jmx/annotation/JmxEndpointDiscoverer.java | 3 +-- .../web/annotation/ControllerEndpointDiscoverer.java | 2 +- .../web/annotation/ServletEndpointDiscoverer.java | 3 +-- .../web/annotation/WebEndpointDiscoverer.java | 3 +-- .../boot/actuate/startup/StartupEndpoint.java | 4 ++-- .../java/org/springframework/boot/AotProcessor.java | 5 ++--- .../org/springframework/boot/WebApplicationType.java | 3 +-- .../boot/env/PropertySourceRuntimeHints.java | 2 +- .../boot/json/JacksonRuntimeHints.java | 9 ++------- .../boot/logging/logback/LogbackRuntimeHints.java | 11 +++-------- .../web/client/ClientHttpRequestFactorySupplier.java | 10 +++++----- 12 files changed, 21 insertions(+), 36 deletions(-) diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/CloudFoundryWebEndpointDiscoverer.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/CloudFoundryWebEndpointDiscoverer.java index ccce390624..76b711a018 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/CloudFoundryWebEndpointDiscoverer.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/CloudFoundryWebEndpointDiscoverer.java @@ -86,7 +86,7 @@ public class CloudFoundryWebEndpointDiscoverer extends WebEndpointDiscoverer { @Override public void registerHints(RuntimeHints hints, ClassLoader classLoader) { hints.reflection().registerType(CloudFoundryEndpointFilter.class, - (hint) -> hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS)); + MemberCategory.INVOKE_DECLARED_CONSTRUCTORS); } } diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/jmx/annotation/JmxEndpointDiscoverer.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/jmx/annotation/JmxEndpointDiscoverer.java index 7dde444a5c..a9843e2af4 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/jmx/annotation/JmxEndpointDiscoverer.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/jmx/annotation/JmxEndpointDiscoverer.java @@ -79,8 +79,7 @@ public class JmxEndpointDiscoverer extends EndpointDiscoverer hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS)); + hints.reflection().registerType(JmxEndpointFilter.class, MemberCategory.INVOKE_DECLARED_CONSTRUCTORS); } } diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/annotation/ControllerEndpointDiscoverer.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/annotation/ControllerEndpointDiscoverer.java index 43b6181207..bb7d11f7b1 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/annotation/ControllerEndpointDiscoverer.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/annotation/ControllerEndpointDiscoverer.java @@ -91,7 +91,7 @@ public class ControllerEndpointDiscoverer extends EndpointDiscoverer hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS)); + MemberCategory.INVOKE_DECLARED_CONSTRUCTORS); } } diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/annotation/ServletEndpointDiscoverer.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/annotation/ServletEndpointDiscoverer.java index 366a55210a..7e9746b19a 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/annotation/ServletEndpointDiscoverer.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/annotation/ServletEndpointDiscoverer.java @@ -89,8 +89,7 @@ public class ServletEndpointDiscoverer extends EndpointDiscoverer hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS)); + hints.reflection().registerType(ServletEndpointFilter.class, MemberCategory.INVOKE_DECLARED_CONSTRUCTORS); } } diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/annotation/WebEndpointDiscoverer.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/annotation/WebEndpointDiscoverer.java index 3c3004e762..7b6dc7f510 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/annotation/WebEndpointDiscoverer.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/annotation/WebEndpointDiscoverer.java @@ -97,8 +97,7 @@ public class WebEndpointDiscoverer extends EndpointDiscoverer hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS)); + hints.reflection().registerType(WebEndpointFilter.class, MemberCategory.INVOKE_DECLARED_CONSTRUCTORS); } } diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/startup/StartupEndpoint.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/startup/StartupEndpoint.java index d035152c98..496c9b1e73 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/startup/StartupEndpoint.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/startup/StartupEndpoint.java @@ -106,9 +106,9 @@ public class StartupEndpoint { @Override public void registerHints(RuntimeHints hints, ClassLoader classLoader) { - hints.reflection().registerType(DEFAULT_TAG, (hint) -> hint.onReachableType(BUFFERED_STARTUP_STEP) + hints.reflection().registerType(DEFAULT_TAG, (typeHint) -> typeHint.onReachableType(BUFFERED_STARTUP_STEP) .withMembers(MemberCategory.INVOKE_PUBLIC_METHODS)); - hints.reflection().registerType(FLIGHT_RECORDER_TAG, (hint) -> hint + hints.reflection().registerType(FLIGHT_RECORDER_TAG, (typeHint) -> typeHint .onReachableType(FLIGHT_RECORDER_STARTUP_STEP).withMembers(MemberCategory.INVOKE_PUBLIC_METHODS)); } diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/AotProcessor.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/AotProcessor.java index 137fe7d1b7..5fc4a720b4 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/AotProcessor.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/AotProcessor.java @@ -153,10 +153,9 @@ public class AotProcessor { TypeReference generatedType = TypeReference.of(generatedInitializerClassName.canonicalName()); TypeReference applicationType = TypeReference.of(this.application); ReflectionHints reflection = generationContext.getRuntimeHints().reflection(); - reflection.registerType(applicationType, (hint) -> { - }); + reflection.registerType(applicationType); reflection.registerType(generatedType, - (hint) -> hint.onReachableType(applicationType).withConstructor(Collections.emptyList())); + (typeHint) -> typeHint.onReachableType(applicationType).withConstructor(Collections.emptyList())); } private Path getRoot(Kind kind) { diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/WebApplicationType.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/WebApplicationType.java index 82ae889035..ca31565f0c 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/WebApplicationType.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/WebApplicationType.java @@ -84,8 +84,7 @@ public enum WebApplicationType { private void registerTypeIfPresent(String typeName, ClassLoader classLoader, RuntimeHints hints) { if (ClassUtils.isPresent(typeName, classLoader)) { - hints.reflection().registerType(TypeReference.of(typeName), (hint) -> { - }); + hints.reflection().registerType(TypeReference.of(typeName)); } } diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/env/PropertySourceRuntimeHints.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/env/PropertySourceRuntimeHints.java index 59412424d3..76b51333dc 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/env/PropertySourceRuntimeHints.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/env/PropertySourceRuntimeHints.java @@ -30,7 +30,7 @@ class PropertySourceRuntimeHints implements RuntimeHintsRegistrar { @Override public void registerHints(RuntimeHints hints, ClassLoader classLoader) { hints.reflection().registerTypeIfPresent(classLoader, "org.yaml.snakeyaml.Yaml", - (hint) -> hint.onReachableType(TypeReference.of(YamlPropertySourceLoader.class))); + (typeHint) -> typeHint.onReachableType(TypeReference.of(YamlPropertySourceLoader.class))); } } diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/json/JacksonRuntimeHints.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/json/JacksonRuntimeHints.java index e25f848e61..6b41c7e4ee 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/json/JacksonRuntimeHints.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/json/JacksonRuntimeHints.java @@ -16,8 +16,6 @@ package org.springframework.boot.json; -import java.util.function.Consumer; - import com.fasterxml.jackson.databind.ser.std.ClassSerializer; import com.fasterxml.jackson.databind.ser.std.FileSerializer; import com.fasterxml.jackson.databind.ser.std.StdJdkSerializers.AtomicBooleanSerializer; @@ -29,7 +27,7 @@ import org.springframework.aot.hint.MemberCategory; import org.springframework.aot.hint.ReflectionHints; import org.springframework.aot.hint.RuntimeHints; import org.springframework.aot.hint.RuntimeHintsRegistrar; -import org.springframework.aot.hint.TypeHint.Builder; +import org.springframework.aot.hint.TypeHint; import org.springframework.aot.hint.TypeReference; import org.springframework.util.ClassUtils; @@ -40,9 +38,6 @@ import org.springframework.util.ClassUtils; */ class JacksonRuntimeHints implements RuntimeHintsRegistrar { - private static final Consumer INVOKE_PUBLIC_CONSTRUCTORS = (hint) -> hint - .withMembers(MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS); - @Override public void registerHints(RuntimeHints hints, ClassLoader classLoader) { if (!ClassUtils.isPresent("com.fasterxml.jackson.databind.ser.BasicSerializerFactory", classLoader)) { @@ -54,7 +49,7 @@ class JacksonRuntimeHints implements RuntimeHintsRegistrar { private void registerSerializers(ReflectionHints hints) { hints.registerTypes(TypeReference.listOf(AtomicBooleanSerializer.class, AtomicIntegerSerializer.class, AtomicLongSerializer.class, FileSerializer.class, ClassSerializer.class, TokenBufferSerializer.class), - INVOKE_PUBLIC_CONSTRUCTORS); + TypeHint.builtWith(MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS)); } } diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/logback/LogbackRuntimeHints.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/logback/LogbackRuntimeHints.java index 35b58c87a6..532a2adf78 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/logback/LogbackRuntimeHints.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/logback/LogbackRuntimeHints.java @@ -16,8 +16,6 @@ package org.springframework.boot.logging.logback; -import java.util.function.Consumer; - import ch.qos.logback.classic.LoggerContext; import ch.qos.logback.classic.pattern.SyslogStartConverter; import ch.qos.logback.core.rolling.helper.DateTokenConverter; @@ -27,7 +25,6 @@ import org.springframework.aot.hint.MemberCategory; import org.springframework.aot.hint.ReflectionHints; import org.springframework.aot.hint.RuntimeHints; import org.springframework.aot.hint.RuntimeHintsRegistrar; -import org.springframework.aot.hint.TypeHint.Builder; import org.springframework.aot.hint.TypeReference; import org.springframework.util.ClassUtils; @@ -38,9 +35,6 @@ import org.springframework.util.ClassUtils; */ class LogbackRuntimeHints implements RuntimeHintsRegistrar { - private static final Consumer DEFAULT_HINT = (hint) -> { - }; - @Override public void registerHints(RuntimeHints hints, ClassLoader classLoader) { if (!ClassUtils.isPresent("ch.qos.logback.classic.LoggerContext", classLoader)) { @@ -53,8 +47,9 @@ class LogbackRuntimeHints implements RuntimeHintsRegistrar { } private void registerHintsForLogbackLoggingSystemTypeChecks(ReflectionHints reflection, ClassLoader classLoader) { - reflection.registerType(LoggerContext.class, DEFAULT_HINT); - reflection.registerTypeIfPresent(classLoader, "org.slf4j.bridge.SLF4JBridgeHandler", DEFAULT_HINT); + reflection.registerType(LoggerContext.class); + reflection.registerTypeIfPresent(classLoader, "org.slf4j.bridge.SLF4JBridgeHandler", (typeHint) -> { + }); } private void registerHintsForBuiltInLogbackConverters(ReflectionHints reflection) { diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/client/ClientHttpRequestFactorySupplier.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/client/ClientHttpRequestFactorySupplier.java index 8fad3048f9..1bdd0fd693 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/client/ClientHttpRequestFactorySupplier.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/client/ClientHttpRequestFactorySupplier.java @@ -61,15 +61,15 @@ public class ClientHttpRequestFactorySupplier implements Supplier callback) { if (ClassUtils.isPresent(APACHE_HTTP_CLIENT_CLASS, classLoader)) { - hints.reflection().registerType(HttpComponentsClientHttpRequestFactory.class, - (hint) -> callback.accept(hint.onReachableType(TypeReference.of(APACHE_HTTP_CLIENT_CLASS)))); + hints.reflection().registerType(HttpComponentsClientHttpRequestFactory.class, (typeHint) -> callback + .accept(typeHint.onReachableType(TypeReference.of(APACHE_HTTP_CLIENT_CLASS)))); } if (ClassUtils.isPresent(OKHTTP_CLIENT_CLASS, classLoader)) { hints.reflection().registerType(OkHttp3ClientHttpRequestFactory.class, - (hint) -> callback.accept(hint.onReachableType(TypeReference.of(OKHTTP_CLIENT_CLASS)))); + (typeHint) -> callback.accept(typeHint.onReachableType(TypeReference.of(OKHTTP_CLIENT_CLASS)))); } - hints.reflection().registerType(SimpleClientHttpRequestFactory.class, (hint) -> callback - .accept(hint.onReachableType(TypeReference.of(SimpleClientHttpRequestFactory.class)))); + hints.reflection().registerType(SimpleClientHttpRequestFactory.class, (typeHint) -> callback + .accept(typeHint.onReachableType(TypeReference.of(SimpleClientHttpRequestFactory.class)))); } }