aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/javassist
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 /src/main/javassist
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.
Diffstat (limited to 'src/main/javassist')
-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
4 files changed, 47 insertions, 8 deletions
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();