Delegate to ReflectionUtils.accessibleConstructor

This commit is contained in:
Juergen Hoeller
2025-06-18 12:20:30 +02:00
parent 00399dc1b3
commit aa525cc3cd
2 changed files with 6 additions and 9 deletions
@@ -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 {
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) {
}
}
@@ -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<? 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);