提交 00098cb8 编写于 作者: S smarks

7195919: (sl) ServiceLoader can throw CCE without needing to create instance

Reviewed-by: ahgross, alanb, dmeetry
上级 6742ab21
......@@ -358,14 +358,21 @@ public final class ServiceLoader<S>
}
String cn = nextName;
nextName = null;
Class<?> c = null;
try {
S p = service.cast(Class.forName(cn, true, loader)
.newInstance());
providers.put(cn, p);
return p;
c = Class.forName(cn, false, loader);
} catch (ClassNotFoundException x) {
fail(service,
"Provider " + cn + " not found");
}
if (!service.isAssignableFrom(c)) {
fail(service,
"Provider " + cn + " not a subtype");
}
try {
S p = service.cast(c.newInstance());
providers.put(cn, p);
return p;
} catch (Throwable x) {
fail(service,
"Provider " + cn + " could not be instantiated: " + x,
......
......@@ -284,12 +284,20 @@ public final class Service<S> {
}
String cn = nextName;
nextName = null;
Class<?> c = null;
try {
return service.cast(Class.forName(cn, true, loader).newInstance());
c = Class.forName(cn, false, loader);
} catch (ClassNotFoundException x) {
fail(service,
"Provider " + cn + " not found");
} catch (Exception x) {
}
if (!service.isAssignableFrom(c)) {
fail(service,
"Provider " + cn + " not a subtype");
}
try {
return service.cast(c.newInstance());
} catch (Throwable x) {
fail(service,
"Provider " + cn + " could not be instantiated: " + x,
x);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册