Skip to content

Commit 77951dc

Browse files
committed
Consistent RuntimeHintsRegistrar signature (plus related polishing)
1 parent 43dd22b commit 77951dc

File tree

11 files changed

+56
-40
lines changed

11 files changed

+56
-40
lines changed

Diff for: spring-context-support/src/main/java/org/springframework/scheduling/quartz/SchedulerFactoryBeanRuntimeHints.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@
2222
import org.springframework.aot.hint.TypeHint.Builder;
2323
import org.springframework.aot.hint.TypeReference;
2424
import org.springframework.aot.hint.annotation.ReflectiveRuntimeHintsRegistrar;
25+
import org.springframework.lang.Nullable;
2526
import org.springframework.util.ClassUtils;
2627

2728
/**
2829
* {@link RuntimeHintsRegistrar} implementation that makes sure {@link SchedulerFactoryBean}
29-
* reflection entries are registered.
30+
* reflection hints are registered.
3031
*
3132
* @author Sebastien Deleuze
3233
* @author Stephane Nicoll
@@ -40,7 +41,7 @@ class SchedulerFactoryBeanRuntimeHints implements RuntimeHintsRegistrar {
4041

4142

4243
@Override
43-
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
44+
public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) {
4445
if (!ClassUtils.isPresent(SCHEDULER_FACTORY_CLASS_NAME, classLoader)) {
4546
return;
4647
}

Diff for: spring-core/src/main/java/org/springframework/aot/hint/annotation/RegisterReflectionForBinding.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -63,7 +63,7 @@
6363
* @see org.springframework.aot.hint.BindingReflectionHintsRegistrar
6464
* @see Reflective @Reflective
6565
*/
66-
@Target({ ElementType.TYPE, ElementType.METHOD })
66+
@Target({ElementType.TYPE, ElementType.METHOD})
6767
@Retention(RetentionPolicy.RUNTIME)
6868
@Documented
6969
@Reflective(RegisterReflectionForBindingProcessor.class)
@@ -77,8 +77,7 @@
7777

7878
/**
7979
* Classes for which reflection hints should be registered.
80-
* <p>At least one class must be specified either via {@link #value} or
81-
* {@code #classes}.
80+
* <p>At least one class must be specified either via {@link #value} or {@code classes}.
8281
* @see #value()
8382
*/
8483
@AliasFor("value")

Diff for: spring-core/src/main/java/org/springframework/aot/hint/support/SpringFactoriesLoaderRuntimeHints.java

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -47,9 +47,11 @@ class SpringFactoriesLoaderRuntimeHints implements RuntimeHintsRegistrar {
4747

4848

4949
@Override
50-
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
50+
public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) {
51+
ClassLoader classLoaderToUse = (classLoader != null ? classLoader :
52+
SpringFactoriesLoaderRuntimeHints.class.getClassLoader());
5153
for (String resourceLocation : RESOURCE_LOCATIONS) {
52-
registerHints(hints, classLoader, resourceLocation);
54+
registerHints(hints, classLoaderToUse, resourceLocation);
5355
}
5456
}
5557

@@ -63,6 +65,7 @@ private void registerHints(RuntimeHints hints, ClassLoader classLoader, String r
6365

6466
private void registerHints(RuntimeHints hints, ClassLoader classLoader,
6567
String factoryClassName, List<String> implementationClassNames) {
68+
6669
Class<?> factoryClass = resolveClassName(classLoader, factoryClassName);
6770
if (factoryClass == null) {
6871
if (logger.isTraceEnabled()) {
@@ -100,6 +103,7 @@ private Class<?> resolveClassName(ClassLoader classLoader, String factoryClassNa
100103
}
101104
}
102105

106+
103107
private static class ExtendedSpringFactoriesLoader extends SpringFactoriesLoader {
104108

105109
ExtendedSpringFactoriesLoader(@Nullable ClassLoader classLoader, Map<String, List<String>> factories) {
@@ -109,7 +113,6 @@ private static class ExtendedSpringFactoriesLoader extends SpringFactoriesLoader
109113
static Map<String, List<String>> accessLoadFactoriesResource(ClassLoader classLoader, String resourceLocation) {
110114
return SpringFactoriesLoader.loadFactoriesResource(classLoader, resourceLocation);
111115
}
112-
113116
}
114117

115118
}

Diff for: spring-jdbc/src/main/java/org/springframework/jdbc/datasource/embedded/EmbeddedDatabaseFactoryRuntimeHints.java

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,19 +21,20 @@
2121
import org.springframework.aot.hint.ExecutableMode;
2222
import org.springframework.aot.hint.RuntimeHints;
2323
import org.springframework.aot.hint.RuntimeHintsRegistrar;
24+
import org.springframework.lang.Nullable;
2425

2526
/**
26-
* {@link RuntimeHintsRegistrar} implementation that registers reflection hints for
27-
* {@code EmbeddedDataSourceProxy#shutdown} in order to allow it to be used as a bean
28-
* destroy method.
27+
* {@link RuntimeHintsRegistrar} implementation that registers reflection hints
28+
* for {@code EmbeddedDataSourceProxy#shutdown} in order to allow it to be used
29+
* as a bean destroy method.
2930
*
3031
* @author Sebastien Deleuze
3132
* @since 6.0
3233
*/
3334
class EmbeddedDatabaseFactoryRuntimeHints implements RuntimeHintsRegistrar {
3435

3536
@Override
36-
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
37+
public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) {
3738
hints.reflection().registerTypeIfPresent(classLoader,
3839
"org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseFactory$EmbeddedDataSourceProxy",
3940
builder -> builder

Diff for: spring-orm/src/main/java/org/springframework/orm/jpa/EntityManagerRuntimeHints.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -22,6 +22,7 @@
2222
import org.springframework.aot.hint.RuntimeHints;
2323
import org.springframework.aot.hint.RuntimeHintsRegistrar;
2424
import org.springframework.aot.hint.TypeReference;
25+
import org.springframework.lang.Nullable;
2526
import org.springframework.util.ClassUtils;
2627

2728
/**
@@ -41,8 +42,9 @@ class EntityManagerRuntimeHints implements RuntimeHintsRegistrar {
4142

4243
private static final String NATIVE_QUERY_IMPL_CLASS_NAME = "org.hibernate.query.sql.internal.NativeQueryImpl";
4344

45+
4446
@Override
45-
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
47+
public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) {
4648
if (ClassUtils.isPresent(HIBERNATE_SESSION_FACTORY_CLASS_NAME, classLoader)) {
4749
hints.proxies().registerJdkProxy(TypeReference.of(HIBERNATE_SESSION_FACTORY_CLASS_NAME),
4850
TypeReference.of(EntityManagerFactoryInfo.class));
@@ -70,4 +72,5 @@ public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
7072
catch (ClassNotFoundException ignored) {
7173
}
7274
}
75+
7376
}

Diff for: spring-tx/src/main/java/org/springframework/transaction/annotation/TransactionRuntimeHints.java

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,11 +21,12 @@
2121
import org.springframework.aot.hint.RuntimeHintsRegistrar;
2222
import org.springframework.aot.hint.TypeHint;
2323
import org.springframework.aot.hint.TypeReference;
24+
import org.springframework.lang.Nullable;
2425
import org.springframework.transaction.TransactionDefinition;
2526

2627
/**
27-
* {@link RuntimeHintsRegistrar} implementation that registers runtime hints for
28-
* transaction management.
28+
* {@link RuntimeHintsRegistrar} implementation that registers runtime hints
29+
* for transaction management.
2930
*
3031
* @author Sebastien Deleuze
3132
* @since 6.0
@@ -34,9 +35,9 @@
3435
class TransactionRuntimeHints implements RuntimeHintsRegistrar {
3536

3637
@Override
37-
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
38-
hints.reflection().registerTypes(TypeReference.listOf(
39-
Isolation.class, Propagation.class, TransactionDefinition.class),
38+
public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) {
39+
hints.reflection().registerTypes(
40+
TypeReference.listOf(Isolation.class, Propagation.class, TransactionDefinition.class),
4041
TypeHint.builtWith(MemberCategory.DECLARED_FIELDS));
4142
}
4243

Diff for: spring-web/src/main/java/org/springframework/http/converter/json/JacksonModulesRuntimeHints.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -22,9 +22,10 @@
2222
import org.springframework.aot.hint.RuntimeHints;
2323
import org.springframework.aot.hint.RuntimeHintsRegistrar;
2424
import org.springframework.aot.hint.TypeHint.Builder;
25+
import org.springframework.lang.Nullable;
2526

2627
/**
27-
* {@link RuntimeHintsRegistrar} implementation that registers reflection entries
28+
* {@link RuntimeHintsRegistrar} implementation that registers reflection hints
2829
* for {@link Jackson2ObjectMapperBuilder} well-known modules.
2930
*
3031
* @author Sebastien Deleuze
@@ -38,7 +39,7 @@ class JacksonModulesRuntimeHints implements RuntimeHintsRegistrar {
3839
.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS);
3940

4041
@Override
41-
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
42+
public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) {
4243
hints.reflection()
4344
.registerTypeIfPresent(classLoader,
4445
"com.fasterxml.jackson.datatype.jdk8.Jdk8Module", asJacksonModule)

Diff for: spring-web/src/main/java/org/springframework/http/converter/json/ProblemDetailRuntimeHints.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,10 +20,11 @@
2020
import org.springframework.aot.hint.RuntimeHints;
2121
import org.springframework.aot.hint.RuntimeHintsRegistrar;
2222
import org.springframework.http.ProblemDetail;
23+
import org.springframework.lang.Nullable;
2324
import org.springframework.util.ClassUtils;
2425

2526
/**
26-
* {@link RuntimeHintsRegistrar} implementation that registers binding reflection entries
27+
* {@link RuntimeHintsRegistrar} implementation that registers binding reflection hints
2728
* for {@link ProblemDetail} serialization support with Jackson.
2829
*
2930
* @author Brian Clozel
@@ -33,7 +34,7 @@
3334
class ProblemDetailRuntimeHints implements RuntimeHintsRegistrar {
3435

3536
@Override
36-
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
37+
public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) {
3738
BindingReflectionHintsRegistrar bindingRegistrar = new BindingReflectionHintsRegistrar();
3839
bindingRegistrar.registerReflectionHints(hints.reflection(), ProblemDetail.class);
3940
if (ClassUtils.isPresent("com.fasterxml.jackson.dataformat.xml.XmlMapper", classLoader)) {

Diff for: spring-web/src/main/java/org/springframework/web/util/WebUtilRuntimeHints.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,18 +19,19 @@
1919
import org.springframework.aot.hint.RuntimeHints;
2020
import org.springframework.aot.hint.RuntimeHintsRegistrar;
2121
import org.springframework.core.io.ClassPathResource;
22+
import org.springframework.lang.Nullable;
2223

2324
/**
24-
* {@link RuntimeHintsRegistrar} implementation that registers resource
25-
* hints for web util resources.
25+
* {@link RuntimeHintsRegistrar} implementation that registers resource hints
26+
* for resources in the {@code web.util} package.
2627
*
2728
* @author Sebastien Deleuze
2829
* @since 6.0
2930
*/
3031
class WebUtilRuntimeHints implements RuntimeHintsRegistrar {
3132

3233
@Override
33-
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
34+
public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) {
3435
hints.resources().registerResource(
3536
new ClassPathResource("HtmlCharacterEntityReferences.properties", getClass()));
3637
}

Diff for: spring-webflux/src/main/java/org/springframework/web/reactive/socket/server/support/HandshakeWebSocketServiceRuntimeHints.java

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,19 +19,21 @@
1919
import org.springframework.aot.hint.MemberCategory;
2020
import org.springframework.aot.hint.RuntimeHints;
2121
import org.springframework.aot.hint.RuntimeHintsRegistrar;
22+
import org.springframework.lang.Nullable;
2223

2324
/**
24-
* {@link RuntimeHintsRegistrar} implementation that registers reflection hints related to
25-
* {@link HandshakeWebSocketService}.
25+
* {@link RuntimeHintsRegistrar} implementation that registers reflection hints
26+
* related to {@link HandshakeWebSocketService}.
2627
*
2728
* @author Sebastien Deleuze
2829
* @since 6.0
2930
*/
3031
class HandshakeWebSocketServiceRuntimeHints implements RuntimeHintsRegistrar {
3132

3233
@Override
33-
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
34+
public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) {
3435
hints.reflection().registerType(HandshakeWebSocketService.initUpgradeStrategy().getClass(),
3536
MemberCategory.INVOKE_DECLARED_CONSTRUCTORS);
3637
}
38+
3739
}

Diff for: spring-websocket/src/main/java/org/springframework/web/socket/server/support/HandshakeHandlerRuntimeHints.java

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,10 +21,11 @@
2121
import org.springframework.aot.hint.RuntimeHints;
2222
import org.springframework.aot.hint.RuntimeHintsRegistrar;
2323
import org.springframework.aot.hint.TypeReference;
24+
import org.springframework.lang.Nullable;
2425
import org.springframework.util.ClassUtils;
2526

2627
/**
27-
* {@link RuntimeHintsRegistrar} implementation that registers reflection entries
28+
* {@link RuntimeHintsRegistrar} implementation that registers reflection hints
2829
* for {@link AbstractHandshakeHandler}.
2930
*
3031
* @author Sebastien Deleuze
@@ -60,8 +61,9 @@ class HandshakeHandlerRuntimeHints implements RuntimeHintsRegistrar {
6061
"com.ibm.websphere.wsoc.WsWsocServerContainer", classLoader);
6162
}
6263

64+
6365
@Override
64-
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
66+
public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) {
6567
ReflectionHints reflectionHints = hints.reflection();
6668
if (tomcatWsPresent) {
6769
registerType(reflectionHints, "org.springframework.web.socket.server.standard.TomcatRequestUpgradeStrategy");
@@ -87,4 +89,5 @@ private void registerType(ReflectionHints reflectionHints, String className) {
8789
reflectionHints.registerType(TypeReference.of(className),
8890
builder -> builder.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS));
8991
}
92+
9093
}

0 commit comments

Comments
 (0)