From a5502d11d14124f6a9ea87b49b9f6eb2718f11f2 Mon Sep 17 00:00:00 2001 From: Patrick Bender Date: Wed, 25 Jul 2018 17:05:52 +0200 Subject: [PATCH 1/2] Fix classloader to also correctly load for example commons-io 2.6 instead of using the included commons-io version --- .../java/edu/cmu/sv/kelinci/instrumentor/Instrumentor.java | 7 ++++++- .../main/java/edu/cmu/sv/kelinci/instrumentor/Options.java | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/instrumentor/src/main/java/edu/cmu/sv/kelinci/instrumentor/Instrumentor.java b/instrumentor/src/main/java/edu/cmu/sv/kelinci/instrumentor/Instrumentor.java index 855e2ec..076b65e 100644 --- a/instrumentor/src/main/java/edu/cmu/sv/kelinci/instrumentor/Instrumentor.java +++ b/instrumentor/src/main/java/edu/cmu/sv/kelinci/instrumentor/Instrumentor.java @@ -2,6 +2,8 @@ import java.io.IOException; import java.io.InputStream; +import java.net.URL; +import java.net.URLClassLoader; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; @@ -27,7 +29,7 @@ public class Instrumentor { public static void main(String[] args) { // get class loader - classloader = Thread.currentThread().getContextClassLoader(); + classloader = new URLClassLoader(new URL[] {}, null); // parse command line arguments Options options = Options.v(); @@ -130,6 +132,9 @@ private static void writeClass(String cls, byte[] bytes) { private static void loadAndWriteResource(String resource) { InputStream is = classloader.getResourceAsStream(resource); + if (is == null) { + is = ClassLoader.getSystemResourceAsStream(resource); + } if (is == null) { System.err.println("Error loading Kelinci classes for addition to output"); return; diff --git a/instrumentor/src/main/java/edu/cmu/sv/kelinci/instrumentor/Options.java b/instrumentor/src/main/java/edu/cmu/sv/kelinci/instrumentor/Options.java index ef0c3c8..4f85ddc 100644 --- a/instrumentor/src/main/java/edu/cmu/sv/kelinci/instrumentor/Options.java +++ b/instrumentor/src/main/java/edu/cmu/sv/kelinci/instrumentor/Options.java @@ -57,7 +57,7 @@ private static void addToClassPath(String url) { File file = new File(url); Method method = URLClassLoader.class.getDeclaredMethod("addURL", new Class[]{URL.class}); method.setAccessible(true); - method.invoke(ClassLoader.getSystemClassLoader(), new Object[]{file.toURI().toURL()}); + method.invoke(Instrumentor.classloader, new Object[]{file.toURI().toURL()}); } catch (Exception e) { throw new RuntimeException("Error adding location to class path: " + url); } From e63a13e4ff6ec415b27312c479a31760576972c8 Mon Sep 17 00:00:00 2001 From: Patrick Bender Date: Wed, 24 Oct 2018 16:57:05 +0200 Subject: [PATCH 2/2] Fixed a problem with the classloader --- .../src/main/java/edu/cmu/sv/kelinci/instrumentor/Options.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/instrumentor/src/main/java/edu/cmu/sv/kelinci/instrumentor/Options.java b/instrumentor/src/main/java/edu/cmu/sv/kelinci/instrumentor/Options.java index 4f85ddc..f7a93c5 100644 --- a/instrumentor/src/main/java/edu/cmu/sv/kelinci/instrumentor/Options.java +++ b/instrumentor/src/main/java/edu/cmu/sv/kelinci/instrumentor/Options.java @@ -57,7 +57,8 @@ private static void addToClassPath(String url) { File file = new File(url); Method method = URLClassLoader.class.getDeclaredMethod("addURL", new Class[]{URL.class}); method.setAccessible(true); - method.invoke(Instrumentor.classloader, new Object[]{file.toURI().toURL()}); + method.invoke(Instrumentor.classloader, new Object[]{file.toURI().toURL()}); + method.invoke(ClassLoader.getSystemClassLoader(), new Object[]{file.toURI().toURL()}); } catch (Exception e) { throw new RuntimeException("Error adding location to class path: " + url); }