Safer classpath building in ImplementationRegistry
This commit is contained in:
parent
623e581623
commit
811b54517a
1 changed files with 7 additions and 9 deletions
|
|
@ -9,11 +9,12 @@ public class ImplementationRegistry {
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T> T getInstance(Class<T> apiClass, String target, String replacement) {
|
public <T> T getInstance(Class<T> apiClass, String target, String replacement) {
|
||||||
|
String base = apiClass.getName();
|
||||||
|
|
||||||
String implName =
|
String implName =
|
||||||
apiClass.getName()
|
base.replaceFirst(
|
||||||
.replace(
|
"org\\.adrianvictor\\.lib",
|
||||||
target,
|
"org.adrianvictor.lib.impl." + classSuffix
|
||||||
replacement + classSuffix + "."
|
|
||||||
);
|
);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
@ -23,10 +24,7 @@ public class ImplementationRegistry {
|
||||||
implClass.getDeclaredConstructor().newInstance()
|
implClass.getDeclaredConstructor().newInstance()
|
||||||
);
|
);
|
||||||
} catch (ReflectiveOperationException e) {
|
} catch (ReflectiveOperationException e) {
|
||||||
throw new IllegalStateException(
|
throw new IllegalStateException("Cannot load " + implName, e);
|
||||||
"Cannot load " + implName,
|
|
||||||
e
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue