From 3290c5528cdb6e263bb43b408f75deb3abd66da7 Mon Sep 17 00:00:00 2001 From: chibash Date: Tue, 2 Aug 2016 12:18:08 +0900 Subject: adds javassist.jar because the unit tests fail without it. --- javassist.jar | Bin 0 -> 724210 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 javassist.jar (limited to 'javassist.jar') diff --git a/javassist.jar b/javassist.jar new file mode 100644 index 00000000..fedb79b0 Binary files /dev/null and b/javassist.jar differ -- cgit v1.2.3 From 9f1d7a2cf0408d92309145a3d63620d64206a38a Mon Sep 17 00:00:00 2001 From: chibash Date: Thu, 4 Aug 2016 01:45:57 +0900 Subject: fixes a bug in ClassClassPath. It was reported in Issue #97. --- javassist.jar | Bin 724210 -> 724191 bytes src/main/javassist/ClassClassPath.java | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) (limited to 'javassist.jar') diff --git a/javassist.jar b/javassist.jar index fedb79b0..ab2bca2c 100644 Binary files a/javassist.jar and b/javassist.jar differ diff --git a/src/main/javassist/ClassClassPath.java b/src/main/javassist/ClassClassPath.java index 86029630..c0a24d35 100644 --- a/src/main/javassist/ClassClassPath.java +++ b/src/main/javassist/ClassClassPath.java @@ -82,7 +82,7 @@ public class ClassClassPath implements ClassPath { */ public InputStream openClassfile(String classname) throws NotFoundException { String filename = '/' + classname.replace('.', '/') + ".class"; - return thisClass.getResourceAsStream('/' + filename); + return thisClass.getResourceAsStream(filename); } /** -- cgit v1.2.3 From fb93ae8b8f6e0646ed9b95d4d8d0abe77d601a62 Mon Sep 17 00:00:00 2001 From: chibash Date: Wed, 28 Sep 2016 00:51:15 +0900 Subject: improves the backward compatibility of LoaderClassPath. LoaderClassPath is modified to show the same behavior in both Java 8 and 9. --- build.xml | 2 +- javassist.jar | Bin 724191 -> 724643 bytes src/main/javassist/ClassPoolTail.java | 3 +- src/main/javassist/CtClass.java | 2 +- src/main/javassist/LoaderClassPath.java | 49 ++++++++++++++++++++++++++++---- src/main/javassist/ModuleClassPath.java | 1 + src/test/javassist/JvstTest5.java | 7 +++++ 7 files changed, 55 insertions(+), 9 deletions(-) (limited to 'javassist.jar') diff --git a/build.xml b/build.xml index e2b8819e..c4d00806 100644 --- a/build.xml +++ b/build.xml @@ -83,7 +83,7 @@ - + This field must be false if the JVM is Java 8 or older. + * + * @since 3.21 + */ + public static boolean fallbackOnModuleClassPath + = javassist.bytecode.ClassFile.MAJOR_VERSION >= javassist.bytecode.ClassFile.JAVA_9; + + private static ModuleClassPath moduleClassPath = null; + + private boolean doFallback; + /** * Creates a search path representing a class loader. */ public LoaderClassPath(ClassLoader cl) { + this(cl, fallbackOnModuleClassPath); + } + + LoaderClassPath(ClassLoader cl, boolean fallback) { clref = new WeakReference(cl); + doFallback = fallback; + if (fallback) + synchronized (LoaderClassPath.class) { + if (moduleClassPath == null) + moduleClassPath = new ModuleClassPath(); + } } public String toString() { @@ -67,13 +96,18 @@ public class LoaderClassPath implements ClassPath { * This method calls getResourceAsStream(String) * on the class loader. */ - public InputStream openClassfile(String classname) { + public InputStream openClassfile(String classname) throws NotFoundException { String cname = classname.replace('.', '/') + ".class"; ClassLoader cl = (ClassLoader)clref.get(); if (cl == null) return null; // not found - else - return cl.getResourceAsStream(cname); + else { + InputStream is = cl.getResourceAsStream(cname); + if (is == null && doFallback) + return moduleClassPath.openClassfile(classname); + else + return is; + } } /** @@ -88,8 +122,13 @@ public class LoaderClassPath implements ClassPath { ClassLoader cl = (ClassLoader)clref.get(); if (cl == null) return null; // not found - else - return cl.getResource(cname); + else { + URL url = cl.getResource(cname); + if (url == null && doFallback) + return moduleClassPath.find(classname); + else + return url; + } } /** diff --git a/src/main/javassist/ModuleClassPath.java b/src/main/javassist/ModuleClassPath.java index c41161f8..20f0e430 100644 --- a/src/main/javassist/ModuleClassPath.java +++ b/src/main/javassist/ModuleClassPath.java @@ -32,6 +32,7 @@ import java.util.Set; * @see ClassPool#appendClassPath(ClassPath) * @see LoaderClassPath * @see ClassClassPath + * @see 3.21 */ public class ModuleClassPath implements ClassPath { private HashMap packages = new HashMap(); diff --git a/src/test/javassist/JvstTest5.java b/src/test/javassist/JvstTest5.java index c1c10d9b..41b640c7 100644 --- a/src/test/javassist/JvstTest5.java +++ b/src/test/javassist/JvstTest5.java @@ -235,4 +235,11 @@ public class JvstTest5 extends JvstTestRoot { Object obj = make(ctClass.getName()); assertEquals(1, invoke(obj, "run")); } + + public void testLoaderClassPath() throws Exception { + ClassPool cp = new ClassPool(); + cp.appendClassPath(new LoaderClassPath(new Loader())); + assertNotNull(cp.get(Object.class.getName())); + assertNotNull(cp.get(this.getClass().getName())); + } } -- cgit v1.2.3