Use try with resource in DelegatingClassLoader
Change-Id: I7cc08ad9cf0516a00d658e9f32f178401a6bb271
This commit is contained in:
@@ -31,13 +31,17 @@ public class DelegatingClassLoader extends ClassLoader {
|
||||
@Override
|
||||
public Class<?> findClass(String name) throws ClassNotFoundException {
|
||||
String path = name.replace('.', '/') + ".class";
|
||||
InputStream resource = target.getResourceAsStream(path);
|
||||
if (resource != null) {
|
||||
try {
|
||||
byte[] bytes = ByteStreams.toByteArray(resource);
|
||||
return defineClass(name, bytes, 0, bytes.length);
|
||||
} catch (IOException e) {
|
||||
try (InputStream resource = target.getResourceAsStream(path)) {
|
||||
if (resource != null) {
|
||||
try {
|
||||
byte[] bytes = ByteStreams.toByteArray(resource);
|
||||
return defineClass(name, bytes, 0, bytes.length);
|
||||
} catch (IOException e) {
|
||||
// throws ClassNotFoundException later
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
// throws ClassNotFoundException later
|
||||
}
|
||||
throw new ClassNotFoundException(name);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user