aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/javassist
diff options
context:
space:
mode:
authorchibash <chiba@javassist.org>2016-12-16 23:22:18 +0900
committerchibash <chiba@javassist.org>2016-12-16 23:22:18 +0900
commit778c463e5aa1795591e56916c6c1c3205317fc3e (patch)
treea0268a523074451842733f84c68f3c88aca38645 /src/main/javassist
parent6a9079aa44cf883b9edc204c64fd0012bf917819 (diff)
downloadjavassist-778c463e5aa1795591e56916c6c1c3205317fc3e.tar.gz
javassist-778c463e5aa1795591e56916c6c1c3205317fc3e.zip
removes javassist.ModuleClassPath.
See #ClassFilesAsResources in JSR 376. We don't need to hack the module system to read a class file in java.lang. http://openjdk.java.net/projects/jigsaw/spec/issues/
Diffstat (limited to 'src/main/javassist')
-rw-r--r--src/main/javassist/ClassClassPath.java4
-rw-r--r--src/main/javassist/ClassPool.java1
-rw-r--r--src/main/javassist/ClassPoolTail.java9
-rw-r--r--src/main/javassist/LoaderClassPath.java40
-rw-r--r--src/main/javassist/ModuleClassPath.java127
5 files changed, 4 insertions, 177 deletions
diff --git a/src/main/javassist/ClassClassPath.java b/src/main/javassist/ClassClassPath.java
index c0a24d35..3befbf4c 100644
--- a/src/main/javassist/ClassClassPath.java
+++ b/src/main/javassist/ClassClassPath.java
@@ -47,12 +47,8 @@ import javassist.bytecode.ClassFile;
* @see ClassPool#insertClassPath(ClassPath)
* @see ClassPool#appendClassPath(ClassPath)
* @see LoaderClassPath
- * @see ModuleClassPath
*/
public class ClassClassPath implements ClassPath {
- private static final boolean useJigsaw
- = ClassFile.MAJOR_VERSION >= ClassFile.JAVA_9;
-
private Class thisClass;
/** Creates a search path.
diff --git a/src/main/javassist/ClassPool.java b/src/main/javassist/ClassPool.java
index c5d3c09a..36e0c337 100644
--- a/src/main/javassist/ClassPool.java
+++ b/src/main/javassist/ClassPool.java
@@ -225,7 +225,6 @@ public class ClassPool {
*
* @see ClassClassPath
* @see LoaderClassPath
- * @see ModuleClassPath
*/
public static synchronized ClassPool getDefault() {
if (defaultPool == null) {
diff --git a/src/main/javassist/ClassPoolTail.java b/src/main/javassist/ClassPoolTail.java
index 3e77f250..13d22d77 100644
--- a/src/main/javassist/ClassPoolTail.java
+++ b/src/main/javassist/ClassPoolTail.java
@@ -240,13 +240,8 @@ final class ClassPoolTail {
}
public ClassPath appendSystemPath() {
- if (javassist.bytecode.ClassFile.MAJOR_VERSION < javassist.bytecode.ClassFile.JAVA_9) {
- return appendClassPath(new ClassClassPath());
- }
- else {
- ClassLoader cl = Thread.currentThread().getContextClassLoader();
- return appendClassPath(new LoaderClassPath(cl, true));
- }
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
+ return appendClassPath(new LoaderClassPath(cl, true));
}
public ClassPath insertClassPath(String pathname)
diff --git a/src/main/javassist/LoaderClassPath.java b/src/main/javassist/LoaderClassPath.java
index daf43c20..6921ca6e 100644
--- a/src/main/javassist/LoaderClassPath.java
+++ b/src/main/javassist/LoaderClassPath.java
@@ -42,45 +42,15 @@ import java.lang.ref.WeakReference;
* @see ClassPool#insertClassPath(ClassPath)
* @see ClassPool#appendClassPath(ClassPath)
* @see ClassClassPath
- * @see ModuleClassPath
*/
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() {
@@ -103,10 +73,7 @@ public class LoaderClassPath implements ClassPath {
return null; // not found
else {
InputStream is = cl.getResourceAsStream(cname);
- if (is == null && doFallback)
- return moduleClassPath.openClassfile(classname);
- else
- return is;
+ return is;
}
}
@@ -124,10 +91,7 @@ public class LoaderClassPath implements ClassPath {
return null; // not found
else {
URL url = cl.getResource(cname);
- if (url == null && doFallback)
- return moduleClassPath.find(classname);
- else
- return url;
+ return url;
}
}
diff --git a/src/main/javassist/ModuleClassPath.java b/src/main/javassist/ModuleClassPath.java
deleted file mode 100644
index 30a77557..00000000
--- a/src/main/javassist/ModuleClassPath.java
+++ /dev/null
@@ -1,127 +0,0 @@
-/*
- * Javassist, a Java-bytecode translator toolkit.
- * Copyright (C) 1999- Shigeru Chiba. All Rights Reserved.
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. Alternatively, the contents of this file may be used under
- * the terms of the GNU Lesser General Public License Version 2.1 or later,
- * or the Apache License Version 2.0.
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- */
-
-package javassist;
-
-import java.io.InputStream;
-import java.lang.reflect.Layer;
-import java.lang.reflect.Module;
-import java.net.URL;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Set;
-
-/**
- * A search-path for obtaining a class file
- * by <code>getResourceAsStream()</code> in <code>java.lang.reflect.Module</code>.
- *
- * @see ClassPool#insertClassPath(ClassPath)
- * @see ClassPool#appendClassPath(ClassPath)
- * @see LoaderClassPath
- * @see ClassClassPath
- * @since 3.21
- */
-public class ModuleClassPath implements ClassPath {
- private HashMap packages = new HashMap();
-
- ModuleClassPath() { this(Layer.boot()); }
-
- /**
- * Constructs a search path.
- *
- * @param layer the layer used to obtain a class file.
- */
- public ModuleClassPath(Layer layer) {
- while (layer != null) {
- Set modules = layer.modules();
- Iterator it = modules.iterator();
- while (it.hasNext())
- addPackages((Module)it.next());
-
- layer = layer.parent().orElse(null);
- }
- }
-
- /**
- * Constructs a search path.
- *
- * @param m the module used to obtain a class file.
- */
- public ModuleClassPath(Module m) {
- addPackages(m);
- }
-
- private void addPackages(Module m) {
- String[] names = m.getPackages();
- for (int i = 0; i < names.length; i++)
- packages.put(names[i], m);
- }
-
- /**
- * Obtains a class file by <code>getResourceAsStream()</code>.
- */
- public InputStream openClassfile(String classname) throws NotFoundException {
- String filename = classname.replace('.', '/') + ".class";
- Module m = (Module)packages.get(getPackageName(classname));
- if (m == null)
- return null;
- else
- try {
- return m.getResourceAsStream(filename);
- }
- catch (java.io.IOException e) {
- throw new NotFoundException(classname, e);
- }
- }
-
- /**
- * Obtains the URL of the specified class file.
- *
- * @return null if the class file could not be found.
- */
- public URL find(String classname) {
- String filename = classname.replace('.', '/') + ".class";
- Module m = (Module)packages.get(getPackageName(classname));
- if (m == null)
- return null;
- else
- try {
- InputStream is = m.getResourceAsStream(filename);
- if (is == null)
- return null;
- else {
- is.close();
- return new URL("jar:file:unknown.jar!/" + filename);
- }
- }
- catch (java.io.IOException e) {
- return null;
- }
- }
-
- private static String getPackageName(String name) {
- int i = name.lastIndexOf('.');
- if (i > 0)
- return name.substring(0, i);
- else
- return "";
- }
-
- /**
- * Does nothing.
- */
- public void close() {}
-}