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