Browse Source

Delegate to ReflectionUtils.accessibleConstructor

pull/35405/head
Juergen Hoeller 6 months ago
parent
commit
aa525cc3cd
  1. 10
      spring-core/src/main/java/org/springframework/aot/hint/annotation/ReflectiveRuntimeHintsRegistrar.java
  2. 5
      spring-core/src/main/java/org/springframework/core/io/support/PropertySourceProcessor.java

10
spring-core/src/main/java/org/springframework/aot/hint/annotation/ReflectiveRuntimeHintsRegistrar.java

@ -130,15 +130,14 @@ public class ReflectiveRuntimeHintsRegistrar { @@ -130,15 +130,14 @@ public class ReflectiveRuntimeHintsRegistrar {
private ReflectiveProcessor instantiateClass(Class<? extends ReflectiveProcessor> type) {
try {
Constructor<? extends ReflectiveProcessor> constructor = type.getDeclaredConstructor();
ReflectionUtils.makeAccessible(constructor);
return constructor.newInstance();
return ReflectionUtils.accessibleConstructor(type).newInstance();
}
catch (Exception ex) {
throw new IllegalStateException("Failed to instantiate " + type, ex);
}
}
private static class DelegatingReflectiveProcessor implements ReflectiveProcessor {
private final Iterable<ReflectiveProcessor> processors;
@ -151,9 +150,10 @@ public class ReflectiveRuntimeHintsRegistrar { @@ -151,9 +150,10 @@ public class ReflectiveRuntimeHintsRegistrar {
public void registerReflectionHints(ReflectionHints hints, AnnotatedElement element) {
this.processors.forEach(processor -> processor.registerReflectionHints(hints, element));
}
}
private record Entry(AnnotatedElement element, ReflectiveProcessor processor) {}
private record Entry(AnnotatedElement element, ReflectiveProcessor processor) {
}
}

5
spring-core/src/main/java/org/springframework/core/io/support/PropertySourceProcessor.java

@ -18,7 +18,6 @@ package org.springframework.core.io.support; @@ -18,7 +18,6 @@ package org.springframework.core.io.support;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.util.ArrayList;
@ -147,9 +146,7 @@ public class PropertySourceProcessor { @@ -147,9 +146,7 @@ public class PropertySourceProcessor {
private static PropertySourceFactory instantiateClass(Class<? extends PropertySourceFactory> type) {
try {
Constructor<? extends PropertySourceFactory> constructor = type.getDeclaredConstructor();
ReflectionUtils.makeAccessible(constructor);
return constructor.newInstance();
return ReflectionUtils.accessibleConstructor(type).newInstance();
}
catch (Exception ex) {
throw new IllegalStateException("Failed to instantiate " + type, ex);

Loading…
Cancel
Save