src/java.base/share/classes/java/net/URLClassLoader.java
Print this page
rev 10608 : 8057936: java.net.URLClassLoader.findClass uses exceptions in control flow
Reviewed-by: michaelm, mr
*** 354,365 ****
* @exception NullPointerException if {@code name} is {@code null}.
*/
protected Class<?> findClass(final String name)
throws ClassNotFoundException
{
try {
! return AccessController.doPrivileged(
new PrivilegedExceptionAction<Class<?>>() {
public Class<?> run() throws ClassNotFoundException {
String path = name.replace('.', '/').concat(".class");
Resource res = ucp.getResource(path, false);
if (res != null) {
--- 354,366 ----
* @exception NullPointerException if {@code name} is {@code null}.
*/
protected Class<?> findClass(final String name)
throws ClassNotFoundException
{
+ final Class<?> result;
try {
! result = AccessController.doPrivileged(
new PrivilegedExceptionAction<Class<?>>() {
public Class<?> run() throws ClassNotFoundException {
String path = name.replace('.', '/').concat(".class");
Resource res = ucp.getResource(path, false);
if (res != null) {
*** 367,383 ****
return defineClass(name, res);
} catch (IOException e) {
throw new ClassNotFoundException(name, e);
}
} else {
! throw new ClassNotFoundException(name);
}
}
}, acc);
} catch (java.security.PrivilegedActionException pae) {
throw (ClassNotFoundException) pae.getException();
}
}
/*
* Retrieve the package using the specified package name.
* If non-null, verify the package using the specified code
--- 368,388 ----
return defineClass(name, res);
} catch (IOException e) {
throw new ClassNotFoundException(name, e);
}
} else {
! return null;
}
}
}, acc);
} catch (java.security.PrivilegedActionException pae) {
throw (ClassNotFoundException) pae.getException();
}
+ if (result == null) {
+ throw new ClassNotFoundException(name);
+ }
+ return result;
}
/*
* Retrieve the package using the specified package name.
* If non-null, verify the package using the specified code