8189264: (sl) ServiceLoader does not wrap Errors thrown by provider classes when running with a security manager

Reviewed-by: mchung
This commit is contained in:
Alan Bateman 2017-10-14 09:51:25 +01:00
parent cae8353ec8
commit e4bea042c5
5 changed files with 92 additions and 11 deletions

View file

@ -747,8 +747,10 @@ public final class ServiceLoader<S>
// invoke factory method with permissions restricted by acc
try {
result = AccessController.doPrivileged(pa, acc);
} catch (PrivilegedActionException pae) {
exc = pae.getCause();
} catch (Throwable x) {
if (x instanceof PrivilegedActionException)
x = x.getCause();
exc = x;
}
}
if (exc != null) {
@ -788,8 +790,10 @@ public final class ServiceLoader<S>
// invoke constructor with permissions restricted by acc
try {
p = AccessController.doPrivileged(pa, acc);
} catch (PrivilegedActionException pae) {
exc = pae.getCause();
} catch (Throwable x) {
if (x instanceof PrivilegedActionException)
x = x.getCause();
exc = x;
}
}
if (exc != null) {
@ -852,8 +856,9 @@ public final class ServiceLoader<S>
PrivilegedExceptionAction<Class<?>> pa = () -> Class.forName(module, cn);
try {
clazz = AccessController.doPrivileged(pa);
} catch (PrivilegedActionException pae) {
Throwable x = pae.getCause();
} catch (Throwable x) {
if (x instanceof PrivilegedActionException)
x = x.getCause();
fail(service, "Unable to load " + cn, x);
return null;
}