Safer classpath building in ImplementationRegistry

This commit is contained in:
天クマ 2026-05-23 15:12:13 -03:00
commit 811b54517a

View file

@ -9,11 +9,12 @@ public class ImplementationRegistry {
}
public <T> T getInstance(Class<T> apiClass, String target, String replacement) {
String base = apiClass.getName();
String implName =
apiClass.getName()
.replace(
target,
replacement + classSuffix + "."
base.replaceFirst(
"org\\.adrianvictor\\.lib",
"org.adrianvictor.lib.impl." + classSuffix
);
try {
@ -23,10 +24,7 @@ public class ImplementationRegistry {
implClass.getDeclaredConstructor().newInstance()
);
} catch (ReflectiveOperationException e) {
throw new IllegalStateException(
"Cannot load " + implName,
e
);
throw new IllegalStateException("Cannot load " + implName, e);
}
}