Safer classpath building in ImplementationRegistry
This commit is contained in:
parent
623e581623
commit
811b54517a
1 changed files with 7 additions and 9 deletions
|
|
@ -9,12 +9,13 @@ 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 {
|
||||
Class<?> implClass = Class.forName(implName);
|
||||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue