aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorchibash <chiba@javassist.org>2016-09-28 00:51:15 +0900
committerchibash <chiba@javassist.org>2016-09-28 00:51:15 +0900
commitfb93ae8b8f6e0646ed9b95d4d8d0abe77d601a62 (patch)
tree4e7c46b44dfd861a084d3917de9fad4a7e883682
parent9f1d7a2cf0408d92309145a3d63620d64206a38a (diff)
downloadjavassist-fb93ae8b8f6e0646ed9b95d4d8d0abe77d601a62.tar.gz
javassist-fb93ae8b8f6e0646ed9b95d4d8d0abe77d601a62.zip
improves the backward compatibility of LoaderClassPath.rel_3_21_0-java9-ea2
LoaderClassPath is modified to show the same behavior in both Java 8 and 9.
-rw-r--r--build.xml2
-rw-r--r--javassist.jarbin724191 -> 724643 bytes
-rw-r--r--src/main/javassist/ClassPoolTail.java3
-rw-r--r--src/main/javassist/CtClass.java2
-rw-r--r--src/main/javassist/LoaderClassPath.java49
-rw-r--r--src/main/javassist/ModuleClassPath.java1
-rw-r--r--src/test/javassist/JvstTest5.java7
7 files changed, 55 insertions, 9 deletions
diff --git a/build.xml b/build.xml
index e2b8819e..c4d00806 100644
--- a/build.xml
+++ b/build.xml
@@ -83,7 +83,7 @@
<classpath refid="classpath"/>
</javac>
</target>
-
+
<target name="test-compile" depends="compile">
<javac srcdir="${test.src.dir}"
destdir="${test.build.dir}"
diff --git a/javassist.jar b/javassist.jar
index ab2bca2c..20b45c6c 100644
--- a/javassist.jar
+++ b/javassist.jar
Binary files differ
diff --git a/src/main/javassist/ClassPoolTail.java b/src/main/javassist/ClassPoolTail.java
index ea148308..3e77f250 100644
--- a/src/main/javassist/ClassPoolTail.java
+++ b/src/main/javassist/ClassPoolTail.java
@@ -245,8 +245,7 @@ final class ClassPoolTail {
}
else {
ClassLoader cl = Thread.currentThread().getContextClassLoader();
- appendClassPath(new LoaderClassPath(cl));
- return appendClassPath(new ModuleClassPath());
+ return appendClassPath(new LoaderClassPath(cl, true));
}
}
diff --git a/src/main/javassist/CtClass.java b/src/main/javassist/CtClass.java
index 716b459b..162ce48f 100644
--- a/src/main/javassist/CtClass.java
+++ b/src/main/javassist/CtClass.java
@@ -69,7 +69,7 @@ public abstract class CtClass {
/**
* The version number of this release.
*/
- public static final String version = "3.21.0-java9";
+ public static final String version = "3.21.0-java9beta2";
/**
* Prints the version number and the copyright notice.
diff --git a/src/main/javassist/LoaderClassPath.java b/src/main/javassist/LoaderClassPath.java
index d516323e..daf43c20 100644
--- a/src/main/javassist/LoaderClassPath.java
+++ b/src/main/javassist/LoaderClassPath.java
@@ -48,10 +48,39 @@ public class LoaderClassPath implements ClassPath {
private WeakReference clref;
/**
+ * If true, this search path implicitly includes
+ * a {@code ModuleClassPath} as a fallback.
+ * For backward compatibility, this field is set to true
+ * if the JVM is Java 9 or later. It can be false in
+ * Java 9 but the behavior of {@code LoadClassPath} will
+ * be different from its behavior in Java 8 or older.
+ *
+ * <p>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 <code>getResourceAsStream(String)</code>
* 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()));
+ }
}