aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/main/javassist/ClassClassPath.java39
-rw-r--r--src/main/javassist/ClassPoolTail.java3
-rw-r--r--src/main/javassist/bytecode/ClassFile.java10
3 files changed, 45 insertions, 7 deletions
diff --git a/src/main/javassist/ClassClassPath.java b/src/main/javassist/ClassClassPath.java
index 3cb8790c..334d61e0 100644
--- a/src/main/javassist/ClassClassPath.java
+++ b/src/main/javassist/ClassClassPath.java
@@ -19,6 +19,8 @@ package javassist;
import java.io.InputStream;
import java.net.URL;
+import javassist.bytecode.ClassFile;
+
/**
* A search-path for obtaining a class file
* by <code>getResourceAsStream()</code> in <code>java.lang.Class</code>.
@@ -43,7 +45,10 @@ import java.net.URL;
* @see LoaderClassPath
*/
public class ClassClassPath implements ClassPath {
- private Class thisClass;
+ private static final boolean useJigsaw
+ = ClassFile.MAJOR_VERSION >= ClassFile.JAVA_9;
+
+ private Class thisClass;
/** Creates a search path.
*
@@ -70,9 +75,17 @@ public class ClassClassPath implements ClassPath {
/**
* Obtains a class file by <code>getResourceAsStream()</code>.
*/
- public InputStream openClassfile(String classname) {
- String jarname = "/" + classname.replace('.', '/') + ".class";
- return thisClass.getResourceAsStream(jarname);
+ public InputStream openClassfile(String classname) throws NotFoundException {
+ String jarname = classname.replace('.', '/') + ".class";
+ if (useJigsaw)
+ try {
+ return thisClass.getModule().getResourceAsStream(jarname);
+ }
+ catch (java.io.IOException e) {
+ throw new NotFoundException(classname, e);
+ }
+ else
+ return thisClass.getResourceAsStream('/' + jarname);
}
/**
@@ -81,8 +94,22 @@ public class ClassClassPath implements ClassPath {
* @return null if the class file could not be found.
*/
public URL find(String classname) {
- String jarname = "/" + classname.replace('.', '/') + ".class";
- return thisClass.getResource(jarname);
+ String jarname = classname.replace('.', '/') + ".class";
+ if (useJigsaw)
+ try {
+ InputStream is = thisClass.getModule().getResourceAsStream(jarname);
+ if (is == null)
+ return null;
+ else {
+ is.close();
+ return new URL("jar:file:unknown.jar!/" + jarname);
+ }
+ }
+ catch (java.io.IOException e) {
+ return null;
+ }
+ else
+ return thisClass.getResource('/' + jarname);
}
/**
diff --git a/src/main/javassist/ClassPoolTail.java b/src/main/javassist/ClassPoolTail.java
index 2fd952b7..e2ace76e 100644
--- a/src/main/javassist/ClassPoolTail.java
+++ b/src/main/javassist/ClassPoolTail.java
@@ -234,7 +234,8 @@ final class ClassPoolTail {
}
public ClassPath appendSystemPath() {
- return appendClassPath(new ClassClassPath());
+ appendClassPath(new ClassClassPath());
+ return appendClassPath(new ClassClassPath(CtClass.class));
}
public ClassPath insertClassPath(String pathname)
diff --git a/src/main/javassist/bytecode/ClassFile.java b/src/main/javassist/bytecode/ClassFile.java
index 887ec7a3..9e7729fd 100644
--- a/src/main/javassist/bytecode/ClassFile.java
+++ b/src/main/javassist/bytecode/ClassFile.java
@@ -118,6 +118,12 @@ public final class ClassFile {
public static final int JAVA_8 = 52;
/**
+ * The major version number of class files
+ * for JDK 1.9.
+ */
+ public static final int JAVA_9 = 53;
+
+ /**
* The major version number of class files created
* from scratch. The default value is 47 (JDK 1.3).
* It is 49 (JDK 1.5)
@@ -128,6 +134,8 @@ public final class ClassFile {
* if the JVM supports <code>java.lang.invoke.CallSite</code>.
* It is 52 (JDK 1.8)
* if the JVM supports <code>java.util.function.Function</code>.
+ * It is 53 (JDK 1.9)
+ * if the JVM supports <code>java.lang.reflect.Module</code>.
*/
public static final int MAJOR_VERSION;
@@ -142,6 +150,8 @@ public final class ClassFile {
ver = JAVA_7;
Class.forName("java.util.function.Function");
ver = JAVA_8;
+ Class.forName("java.lang.reflect.Module");
+ ver = JAVA_9;
}
catch (Throwable t) {}
MAJOR_VERSION = ver;