mirror of
https://github.com/xerial/snappy-java.git
synced 2025-07-25 15:04:32 +02:00
Traverse ancestor class loader
This commit is contained in:
parent
b531cb36dc
commit
4a7694e295
@ -84,6 +84,14 @@ public class SnappyLoader
|
|||||||
private static boolean isInitialized = false;
|
private static boolean isInitialized = false;
|
||||||
private static boolean isLoaded = false;
|
private static boolean isLoaded = false;
|
||||||
|
|
||||||
|
private static ClassLoader getAncestorClassLoader() {
|
||||||
|
ClassLoader cl = SnappyLoader.class.getClassLoader();
|
||||||
|
while (cl.getParent() != null) {
|
||||||
|
cl = cl.getParent();
|
||||||
|
}
|
||||||
|
return cl;
|
||||||
|
}
|
||||||
|
|
||||||
private static byte[] getByteCode(String resourcePath) throws IOException {
|
private static byte[] getByteCode(String resourcePath) throws IOException {
|
||||||
|
|
||||||
InputStream in = SnappyLoader.class.getResourceAsStream(resourcePath);
|
InputStream in = SnappyLoader.class.getResourceAsStream(resourcePath);
|
||||||
@ -134,7 +142,7 @@ public class SnappyLoader
|
|||||||
Method defineClass = classLoader.getDeclaredMethod("defineClass", new Class[] { String.class,
|
Method defineClass = classLoader.getDeclaredMethod("defineClass", new Class[] { String.class,
|
||||||
byte[].class, int.class, int.class, ProtectionDomain.class });
|
byte[].class, int.class, int.class, ProtectionDomain.class });
|
||||||
|
|
||||||
ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader();
|
ClassLoader systemClassLoader = getAncestorClassLoader();
|
||||||
// ClassLoader.defineClass is a protected method, so we have to make it accessible
|
// ClassLoader.defineClass is a protected method, so we have to make it accessible
|
||||||
defineClass.setAccessible(true);
|
defineClass.setAccessible(true);
|
||||||
try {
|
try {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user