diff --git a/spring-core/src/main/java/org/springframework/aot/hint/annotation/ReflectiveRuntimeHintsRegistrar.java b/spring-core/src/main/java/org/springframework/aot/hint/annotation/ReflectiveRuntimeHintsRegistrar.java index b57ac1828c7..565c35182d9 100644 --- a/spring-core/src/main/java/org/springframework/aot/hint/annotation/ReflectiveRuntimeHintsRegistrar.java +++ b/spring-core/src/main/java/org/springframework/aot/hint/annotation/ReflectiveRuntimeHintsRegistrar.java @@ -130,15 +130,14 @@ public class ReflectiveRuntimeHintsRegistrar { private ReflectiveProcessor instantiateClass(Class type) { try { - Constructor 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 processors; @@ -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) { + } } diff --git a/spring-core/src/main/java/org/springframework/core/io/support/PropertySourceProcessor.java b/spring-core/src/main/java/org/springframework/core/io/support/PropertySourceProcessor.java index 9e27a0df642..55436e0f340 100644 --- a/spring-core/src/main/java/org/springframework/core/io/support/PropertySourceProcessor.java +++ b/spring-core/src/main/java/org/springframework/core/io/support/PropertySourceProcessor.java @@ -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 { private static PropertySourceFactory instantiateClass(Class type) { try { - Constructor 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);