diff options
54 files changed, 389 insertions, 167 deletions
@@ -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 Binary files differindex 3fb75e6a..40f6a448 100644 --- a/javassist.jar +++ b/javassist.jar @@ -7,7 +7,7 @@ Javassist (JAVA programming ASSISTant) makes Java bytecode manipulation simple. It is a class library for editing bytecodes in Java. </description> - <version>3.21.0-GA</version> + <version>3.22.0-CR1</version> <name>Javassist</name> <url>http://www.javassist.org/</url> @@ -145,8 +145,8 @@ <configuration> <source>1.6</source> <target>1.6</target> - <testSource>1.8</testSource> - <testTarget>1.8</testTarget> + <testSource>1.9</testSource> + <testTarget>1.9</testTarget> <testCompilerArgument>-parameters</testCompilerArgument> </configuration> </plugin> @@ -269,9 +269,7 @@ <profile> <id>default-tools</id> <activation> - <os> - <family>!mac</family> - </os> + <jdk>[,1.8]</jdk> </activation> <dependencies> <dependency> @@ -285,11 +283,9 @@ </dependencies> </profile> <profile> - <id>mac-tools</id> + <id>java9-tools</id> <activation> - <os> - <family>mac</family> - </os> + <jdk>[1.9,]</jdk> </activation> <dependencies> <dependency> @@ -298,7 +294,7 @@ <version>${java.version}</version> <scope>system</scope> <optional>true</optional> - <systemPath>${java.home}/../lib/tools.jar</systemPath> + <systemPath>${java.home}/jrt-fs.jar</systemPath> </dependency> </dependencies> </profile> diff --git a/src/main/javassist/ClassClassPath.java b/src/main/javassist/ClassClassPath.java index 3cb8790c..c0a24d35 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>. @@ -38,11 +40,19 @@ import java.net.URL; * <code>ClassClassPath</code> uses a class object representing * the class including the code snippet above. * + * <p>Class files in a named module are private to that module. + * This method cannot obtain class files in named modules. + * </p> + * * @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. @@ -70,9 +80,9 @@ 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 filename = '/' + classname.replace('.', '/') + ".class"; + return thisClass.getResourceAsStream(filename); } /** @@ -81,8 +91,8 @@ 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 filename = '/' + classname.replace('.', '/') + ".class"; + return thisClass.getResource(filename); } /** diff --git a/src/main/javassist/ClassPool.java b/src/main/javassist/ClassPool.java index c90c2c74..c5d3c09a 100644 --- a/src/main/javassist/ClassPool.java +++ b/src/main/javassist/ClassPool.java @@ -220,10 +220,12 @@ public class ClassPool { * </pre> * * <p>If the default class pool cannot find any class files, - * try <code>ClassClassPath</code> and <code>LoaderClassPath</code>. + * try <code>ClassClassPath</code>, <code>ModuleClassPath</code>, + * or <code>LoaderClassPath</code>. * * @see ClassClassPath * @see LoaderClassPath + * @see ModuleClassPath */ public static synchronized ClassPool getDefault() { if (defaultPool == null) { @@ -1152,13 +1154,13 @@ public class ClassPool { Object[] args; if (domain == null) { method = defineClass1; - args = new Object[] { ct.getName(), b, new Integer(0), - new Integer(b.length)}; + args = new Object[] { ct.getName(), b, Integer.valueOf(0), + Integer.valueOf(b.length)}; } else { method = defineClass2; - args = new Object[] { ct.getName(), b, new Integer(0), - new Integer(b.length), domain}; + args = new Object[] { ct.getName(), b, Integer.valueOf(0), + Integer.valueOf(b.length), domain}; } return (Class)toClass2(method, loader, args); diff --git a/src/main/javassist/ClassPoolTail.java b/src/main/javassist/ClassPoolTail.java index 2fd952b7..3e77f250 100644 --- a/src/main/javassist/ClassPoolTail.java +++ b/src/main/javassist/ClassPoolTail.java @@ -16,11 +16,17 @@ package javassist; -import java.io.*; -import java.util.jar.*; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FilenameFilter; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; import java.net.MalformedURLException; import java.net.URL; -import java.util.Hashtable; +import java.util.jar.JarEntry; +import java.util.jar.JarFile; final class ClassPathList { ClassPathList next; @@ -234,7 +240,13 @@ final class ClassPoolTail { } public ClassPath appendSystemPath() { - return appendClassPath(new ClassClassPath()); + 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)); + } } public ClassPath insertClassPath(String pathname) diff --git a/src/main/javassist/CtClass.java b/src/main/javassist/CtClass.java index 31e86044..4ff04c0e 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-GA"; + public static final String version = "3.22.0-CR1"; /** * Prints the version number and the copyright notice. diff --git a/src/main/javassist/CtField.java b/src/main/javassist/CtField.java index 15a6d6f0..f9d8051b 100644 --- a/src/main/javassist/CtField.java +++ b/src/main/javassist/CtField.java @@ -416,18 +416,18 @@ public class CtField extends CtMember { ConstPool cp = fieldInfo.getConstPool(); switch (cp.getTag(index)) { case ConstPool.CONST_Long : - return new Long(cp.getLongInfo(index)); + return Long.valueOf(cp.getLongInfo(index)); case ConstPool.CONST_Float : - return new Float(cp.getFloatInfo(index)); + return Float.valueOf(cp.getFloatInfo(index)); case ConstPool.CONST_Double : - return new Double(cp.getDoubleInfo(index)); + return Double.valueOf(cp.getDoubleInfo(index)); case ConstPool.CONST_Integer : int value = cp.getIntegerInfo(index); // "Z" means boolean type. if ("Z".equals(fieldInfo.getDescriptor())) - return new Boolean(value != 0); + return Boolean.valueOf(value != 0); else - return new Integer(value); + return Integer.valueOf(value); case ConstPool.CONST_String : return cp.getStringInfo(index); default : diff --git a/src/main/javassist/LoaderClassPath.java b/src/main/javassist/LoaderClassPath.java index a1580537..daf43c20 100644 --- a/src/main/javassist/LoaderClassPath.java +++ b/src/main/javassist/LoaderClassPath.java @@ -31,6 +31,10 @@ import java.lang.ref.WeakReference; * * <p>The given class loader must have both <code>getResourceAsStream()</code> * and <code>getResource()</code>. + * + * <p>Class files in a named module are private to that module. + * This method cannot obtain class files in named modules. + * </p> * * @author <a href="mailto:bill@jboss.org">Bill Burke</a> * @author Shigeru Chiba @@ -38,15 +42,45 @@ 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() { @@ -62,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; + } } /** @@ -83,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 new file mode 100644 index 00000000..20f0e430 --- /dev/null +++ b/src/main/javassist/ModuleClassPath.java @@ -0,0 +1,127 @@ +/* + * 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 + * @see 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() {} +} diff --git a/src/main/javassist/bytecode/ClassFile.java b/src/main/javassist/bytecode/ClassFile.java index 5e0cba4d..d97ac735 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; diff --git a/src/main/javassist/bytecode/ConstPool.java b/src/main/javassist/bytecode/ConstPool.java index 06df1327..86d7eb40 100644 --- a/src/main/javassist/bytecode/ConstPool.java +++ b/src/main/javassist/bytecode/ConstPool.java @@ -567,13 +567,13 @@ public final class ConstPool { if (constInfo instanceof StringInfo) value = this.getStringInfo(index); else if (constInfo instanceof FloatInfo) - value = new Float(getFloatInfo(index)); + value = Float.valueOf(getFloatInfo(index)); else if (constInfo instanceof IntegerInfo) - value = new Integer(getIntegerInfo(index)); + value = Integer.valueOf(getIntegerInfo(index)); else if (constInfo instanceof LongInfo) - value = new Long(getLongInfo(index)); + value = Long.valueOf(getLongInfo(index)); else if (constInfo instanceof DoubleInfo) - value = new Double(getDoubleInfo(index)); + value = Double.valueOf(getDoubleInfo(index)); else value = null; diff --git a/src/main/javassist/bytecode/analysis/Subroutine.java b/src/main/javassist/bytecode/analysis/Subroutine.java index ca0d1737..381ed6ab 100644 --- a/src/main/javassist/bytecode/analysis/Subroutine.java +++ b/src/main/javassist/bytecode/analysis/Subroutine.java @@ -34,11 +34,11 @@ public class Subroutine { public Subroutine(int start, int caller) { this.start = start; - callers.add(new Integer(caller)); + callers.add(Integer.valueOf(caller)); } public void addCaller(int caller) { - callers.add(new Integer(caller)); + callers.add(Integer.valueOf(caller)); } public int start() { @@ -46,11 +46,11 @@ public class Subroutine { } public void access(int index) { - access.add(new Integer(index)); + access.add(Integer.valueOf(index)); } public boolean isAccessed(int index) { - return access.contains(new Integer(index)); + return access.contains(Integer.valueOf(index)); } public Collection accessed() { diff --git a/src/main/javassist/bytecode/analysis/SubroutineScanner.java b/src/main/javassist/bytecode/analysis/SubroutineScanner.java index 8cf688f5..c0af816a 100644 --- a/src/main/javassist/bytecode/analysis/SubroutineScanner.java +++ b/src/main/javassist/bytecode/analysis/SubroutineScanner.java @@ -62,10 +62,10 @@ public class SubroutineScanner implements Opcode { private void scan(int pos, CodeIterator iter, Subroutine sub) throws BadBytecode { // Skip already processed blocks - if (done.contains(new Integer(pos))) + if (done.contains(Integer.valueOf(pos))) return; - done.add(new Integer(pos)); + done.add(Integer.valueOf(pos)); int old = iter.lookAhead(); iter.move(pos); @@ -103,10 +103,10 @@ public class SubroutineScanner implements Opcode { if (Util.isJumpInstruction(opcode)) { int target = Util.getJumpTarget(pos, iter); if (opcode == JSR || opcode == JSR_W) { - Subroutine s = (Subroutine) subTable.get(new Integer(target)); + Subroutine s = (Subroutine) subTable.get(Integer.valueOf(target)); if (s == null) { s = new Subroutine(target, pos); - subTable.put(new Integer(target), s); + subTable.put(Integer.valueOf(target), s); scan(target, iter, s); } else { s.addCaller(pos); diff --git a/src/main/javassist/bytecode/annotation/AnnotationImpl.java b/src/main/javassist/bytecode/annotation/AnnotationImpl.java index dabf1f44..babac927 100644 --- a/src/main/javassist/bytecode/annotation/AnnotationImpl.java +++ b/src/main/javassist/bytecode/annotation/AnnotationImpl.java @@ -131,12 +131,12 @@ public class AnnotationImpl implements InvocationHandler { if (Object.class == method.getDeclaringClass()) { if ("equals".equals(name)) { Object obj = args[0]; - return new Boolean(checkEquals(obj)); + return Boolean.valueOf(checkEquals(obj)); } else if ("toString".equals(name)) return annotation.toString(); else if ("hashCode".equals(name)) - return new Integer(hashCode()); + return Integer.valueOf(hashCode()); } else if ("annotationType".equals(name) && method.getParameterTypes().length == 0) diff --git a/src/main/javassist/bytecode/annotation/BooleanMemberValue.java b/src/main/javassist/bytecode/annotation/BooleanMemberValue.java index 17756900..b005ad5a 100644 --- a/src/main/javassist/bytecode/annotation/BooleanMemberValue.java +++ b/src/main/javassist/bytecode/annotation/BooleanMemberValue.java @@ -59,7 +59,7 @@ public class BooleanMemberValue extends MemberValue { } Object getValue(ClassLoader cl, ClassPool cp, Method m) { - return new Boolean(getValue()); + return Boolean.valueOf(getValue()); } Class getType(ClassLoader cl) { diff --git a/src/main/javassist/bytecode/annotation/ByteMemberValue.java b/src/main/javassist/bytecode/annotation/ByteMemberValue.java index 63aad72a..d0fb5c61 100644 --- a/src/main/javassist/bytecode/annotation/ByteMemberValue.java +++ b/src/main/javassist/bytecode/annotation/ByteMemberValue.java @@ -59,7 +59,7 @@ public class ByteMemberValue extends MemberValue { } Object getValue(ClassLoader cl, ClassPool cp, Method m) { - return new Byte(getValue()); + return Byte.valueOf(getValue()); } Class getType(ClassLoader cl) { diff --git a/src/main/javassist/bytecode/annotation/CharMemberValue.java b/src/main/javassist/bytecode/annotation/CharMemberValue.java index 1b991d29..ce5d4199 100644 --- a/src/main/javassist/bytecode/annotation/CharMemberValue.java +++ b/src/main/javassist/bytecode/annotation/CharMemberValue.java @@ -60,7 +60,7 @@ public class CharMemberValue extends MemberValue { } Object getValue(ClassLoader cl, ClassPool cp, Method m) { - return new Character(getValue()); + return Character.valueOf(getValue()); } Class getType(ClassLoader cl) { diff --git a/src/main/javassist/bytecode/annotation/DoubleMemberValue.java b/src/main/javassist/bytecode/annotation/DoubleMemberValue.java index f8b417fa..0f18a72d 100644 --- a/src/main/javassist/bytecode/annotation/DoubleMemberValue.java +++ b/src/main/javassist/bytecode/annotation/DoubleMemberValue.java @@ -61,7 +61,7 @@ public class DoubleMemberValue extends MemberValue { } Object getValue(ClassLoader cl, ClassPool cp, Method m) { - return new Double(getValue()); + return Double.valueOf(getValue()); } Class getType(ClassLoader cl) { diff --git a/src/main/javassist/bytecode/annotation/FloatMemberValue.java b/src/main/javassist/bytecode/annotation/FloatMemberValue.java index 35152fdd..3bf07ef0 100644 --- a/src/main/javassist/bytecode/annotation/FloatMemberValue.java +++ b/src/main/javassist/bytecode/annotation/FloatMemberValue.java @@ -61,7 +61,7 @@ public class FloatMemberValue extends MemberValue { } Object getValue(ClassLoader cl, ClassPool cp, Method m) { - return new Float(getValue()); + return Float.valueOf(getValue()); } Class getType(ClassLoader cl) { diff --git a/src/main/javassist/bytecode/annotation/IntegerMemberValue.java b/src/main/javassist/bytecode/annotation/IntegerMemberValue.java index 6783b827..83e4e70f 100644 --- a/src/main/javassist/bytecode/annotation/IntegerMemberValue.java +++ b/src/main/javassist/bytecode/annotation/IntegerMemberValue.java @@ -66,7 +66,7 @@ public class IntegerMemberValue extends MemberValue { } Object getValue(ClassLoader cl, ClassPool cp, Method m) { - return new Integer(getValue()); + return Integer.valueOf(getValue()); } Class getType(ClassLoader cl) { diff --git a/src/main/javassist/bytecode/annotation/LongMemberValue.java b/src/main/javassist/bytecode/annotation/LongMemberValue.java index eafb5b82..7f0c6fec 100644 --- a/src/main/javassist/bytecode/annotation/LongMemberValue.java +++ b/src/main/javassist/bytecode/annotation/LongMemberValue.java @@ -60,7 +60,7 @@ public class LongMemberValue extends MemberValue { } Object getValue(ClassLoader cl, ClassPool cp, Method m) { - return new Long(getValue()); + return Long.valueOf(getValue()); } Class getType(ClassLoader cl) { diff --git a/src/main/javassist/bytecode/annotation/ShortMemberValue.java b/src/main/javassist/bytecode/annotation/ShortMemberValue.java index 909c09ee..82a6f59e 100644 --- a/src/main/javassist/bytecode/annotation/ShortMemberValue.java +++ b/src/main/javassist/bytecode/annotation/ShortMemberValue.java @@ -60,7 +60,7 @@ public class ShortMemberValue extends MemberValue { } Object getValue(ClassLoader cl, ClassPool cp, Method m) { - return new Short(getValue()); + return Short.valueOf(getValue()); } Class getType(ClassLoader cl) { diff --git a/src/main/javassist/bytecode/stackmap/BasicBlock.java b/src/main/javassist/bytecode/stackmap/BasicBlock.java index 79ec5a77..7a643609 100644 --- a/src/main/javassist/bytecode/stackmap/BasicBlock.java +++ b/src/main/javassist/bytecode/stackmap/BasicBlock.java @@ -196,7 +196,7 @@ public class BasicBlock { private Mark makeMark0(HashMap table, int pos, boolean isBlockBegin, boolean isTarget) { - Integer p = new Integer(pos); + Integer p = Integer.valueOf(pos); Mark m = (Mark)table.get(p); if (m == null) { m = new Mark(pos); diff --git a/src/main/javassist/compiler/CodeGen.java b/src/main/javassist/compiler/CodeGen.java index e02884de..ab02d8cf 100644 --- a/src/main/javassist/compiler/CodeGen.java +++ b/src/main/javassist/compiler/CodeGen.java @@ -595,7 +595,7 @@ public abstract class CodeGen extends Visitor implements Opcode, TokenId { "sorry, not support labeled break or continue"); bytecode.addOpcode(Opcode.GOTO); - Integer pc = new Integer(bytecode.currentPc()); + Integer pc = Integer.valueOf(bytecode.currentPc()); bytecode.addIndex(0); if (notCont) breakList.add(pc); diff --git a/src/main/javassist/compiler/KeywordTable.java b/src/main/javassist/compiler/KeywordTable.java index 3f0025fe..5f516e3d 100644 --- a/src/main/javassist/compiler/KeywordTable.java +++ b/src/main/javassist/compiler/KeywordTable.java @@ -28,6 +28,6 @@ public final class KeywordTable extends java.util.HashMap { } public void append(String name, int t) { - put(name, new Integer(t)); + put(name, Integer.valueOf(t)); } } diff --git a/src/main/javassist/compiler/MemberCodeGen.java b/src/main/javassist/compiler/MemberCodeGen.java index b1f932ca..07c113a3 100644 --- a/src/main/javassist/compiler/MemberCodeGen.java +++ b/src/main/javassist/compiler/MemberCodeGen.java @@ -209,7 +209,7 @@ public class MemberCodeGen extends CodeGen { boolean tryNotReturn = !hasReturned; if (tryNotReturn) { bc.addOpcode(Opcode.GOTO); - gotoList.add(new Integer(bc.currentPc())); + gotoList.add(Integer.valueOf(bc.currentPc())); bc.addIndex(0); // correct later } @@ -235,7 +235,7 @@ public class MemberCodeGen extends CodeGen { if (!hasReturned) { bc.addOpcode(Opcode.GOTO); - gotoList.add(new Integer(bc.currentPc())); + gotoList.add(Integer.valueOf(bc.currentPc())); bc.addIndex(0); // correct later tryNotReturn = true; } diff --git a/src/main/javassist/tools/rmi/ObjectImporter.java b/src/main/javassist/tools/rmi/ObjectImporter.java index 476ec3c8..43b62039 100644 --- a/src/main/javassist/tools/rmi/ObjectImporter.java +++ b/src/main/javassist/tools/rmi/ObjectImporter.java @@ -189,7 +189,7 @@ public class ObjectImporter implements java.io.Serializable { private Object createProxy(int oid, String classname) throws Exception { Class c = Class.forName(classname); Constructor cons = c.getConstructor(proxyConstructorParamTypes); - return cons.newInstance(new Object[] { this, new Integer(oid) }); + return cons.newInstance(new Object[] { this, Integer.valueOf(oid) }); } /** diff --git a/src/main/javassist/util/proxy/FactoryHelper.java b/src/main/javassist/util/proxy/FactoryHelper.java index 9b2b791c..b17b78ed 100644 --- a/src/main/javassist/util/proxy/FactoryHelper.java +++ b/src/main/javassist/util/proxy/FactoryHelper.java @@ -152,13 +152,13 @@ public class FactoryHelper { Object[] args; if (domain == null) { method = defineClass1; - args = new Object[] { cf.getName(), b, new Integer(0), - new Integer(b.length) }; + args = new Object[] { cf.getName(), b, Integer.valueOf(0), + Integer.valueOf(b.length) }; } else { method = defineClass2; - args = new Object[] { cf.getName(), b, new Integer(0), - new Integer(b.length), domain }; + args = new Object[] { cf.getName(), b, Integer.valueOf(0), + Integer.valueOf(b.length), domain }; } return toClass2(method, loader, args); diff --git a/src/main/javassist/util/proxy/SerializedProxy.java b/src/main/javassist/util/proxy/SerializedProxy.java index 36425a88..a0485da0 100644 --- a/src/main/javassist/util/proxy/SerializedProxy.java +++ b/src/main/javassist/util/proxy/SerializedProxy.java @@ -17,6 +17,7 @@ package javassist.util.proxy; import java.io.Serializable; +import java.lang.reflect.InvocationTargetException; import java.io.ObjectStreamException; import java.security.AccessController; import java.security.PrivilegedActionException; @@ -82,10 +83,16 @@ class SerializedProxy implements Serializable { ProxyFactory f = new ProxyFactory(); f.setSuperclass(loadClass(superClass)); f.setInterfaces(infs); - Proxy proxy = (Proxy)f.createClass(filterSignature).newInstance(); + Proxy proxy = (Proxy)f.createClass(filterSignature).getConstructor().newInstance(); proxy.setHandler(handler); return proxy; } + catch (NoSuchMethodException e) { + throw new java.io.InvalidClassException(e.getMessage()); + } + catch (InvocationTargetException e) { + throw new java.io.InvalidClassException(e.getMessage()); + } catch (ClassNotFoundException e) { throw new java.io.InvalidClassException(e.getMessage()); } diff --git a/src/test/Test.java b/src/test/Test.java index c21d930f..b01a6211 100644 --- a/src/test/Test.java +++ b/src/test/Test.java @@ -48,7 +48,7 @@ public class Test { ctClass.debugWriteFile(); Class<?> cc = ctClass.toClass(); System.out.println(cc.getName()); - InvalidStackMapFrame obj = (InvalidStackMapFrame)cc.newInstance(); + InvalidStackMapFrame obj = (InvalidStackMapFrame)cc.getDeclaredConstructor().newInstance(); obj.bytecodeVerifyError(); } } diff --git a/src/test/javassist/JvstTest.java b/src/test/javassist/JvstTest.java index 9a671de6..eb57a643 100644 --- a/src/test/javassist/JvstTest.java +++ b/src/test/javassist/JvstTest.java @@ -1041,7 +1041,7 @@ public class JvstTest extends JvstTestRoot { } public void testPackage() throws Exception { - Object obj = new Loader().loadClass("test1.Pac").newInstance(); + Object obj = new Loader().loadClass("test1.Pac").getConstructor().newInstance(); assertEquals(1, invoke(obj, "run")); } diff --git a/src/test/javassist/JvstTest2.java b/src/test/javassist/JvstTest2.java index 4ff84784..10d5d3e3 100644 --- a/src/test/javassist/JvstTest2.java +++ b/src/test/javassist/JvstTest2.java @@ -1423,32 +1423,32 @@ public class JvstTest2 extends JvstTestRoot { CtField f = new CtField(CtClass.intType, "sff1", cc); f.setModifiers(Modifier.STATIC | Modifier.FINAL); cc.addField(f, "5"); - assertEquals(new Integer(5), f.getConstantValue()); + assertEquals(Integer.valueOf(5), f.getConstantValue()); f = new CtField(CtClass.longType, "sff2", cc); f.setModifiers(Modifier.STATIC | Modifier.FINAL); cc.addField(f, "6"); - assertEquals(new Long(6), f.getConstantValue()); + assertEquals(Long.valueOf(6), f.getConstantValue()); f = new CtField(CtClass.floatType, "sff3", cc); f.setModifiers(Modifier.STATIC | Modifier.FINAL); cc.addField(f, "7"); - assertEquals(new Float(7.0F), f.getConstantValue()); + assertEquals(Float.valueOf(7.0F), f.getConstantValue()); f = new CtField(CtClass.floatType, "sff4", cc); f.setModifiers(Modifier.STATIC | Modifier.FINAL); cc.addField(f, "8.0"); - assertEquals(new Float(8.0F), f.getConstantValue()); + assertEquals(Float.valueOf(8.0F), f.getConstantValue()); f = new CtField(CtClass.doubleType, "sff5", cc); f.setModifiers(Modifier.STATIC | Modifier.FINAL); cc.addField(f, "9"); - assertEquals(new Double(9.0), f.getConstantValue()); + assertEquals(Double.valueOf(9.0), f.getConstantValue()); f = new CtField(CtClass.doubleType, "sff6", cc); f.setModifiers(Modifier.STATIC | Modifier.FINAL); cc.addField(f, "10.0"); - assertEquals(new Double(10.0), f.getConstantValue()); + assertEquals(Double.valueOf(10.0), f.getConstantValue()); f = new CtField(sloader.get("java.lang.String"), "sff7", cc); f.setModifiers(Modifier.STATIC | Modifier.FINAL); diff --git a/src/test/javassist/JvstTest3.java b/src/test/javassist/JvstTest3.java index 427479d1..056df5c2 100644 --- a/src/test/javassist/JvstTest3.java +++ b/src/test/javassist/JvstTest3.java @@ -852,7 +852,7 @@ public class JvstTest3 extends JvstTestRoot { { java.lang.reflect.Method m = target.getClass().getMethod(method, new Class[] { long.class, int.class }); - Object res = m.invoke(target, new Object[] { new Long(arg1), new Integer(arg2)}); + Object res = m.invoke(target, new Object[] { Long.valueOf(arg1), Integer.valueOf(arg2)}); return ((Integer)res).intValue(); } @@ -861,7 +861,7 @@ public class JvstTest3 extends JvstTestRoot { { java.lang.reflect.Method m = target.getClass().getMethod(method, new Class[] { int.class, double.class }); - Object res = m.invoke(target, new Object[] { new Integer(arg1), new Double(arg2)}); + Object res = m.invoke(target, new Object[] { Integer.valueOf(arg1), Double.valueOf(arg2)}); return ((Integer)res).intValue(); } @@ -870,7 +870,7 @@ public class JvstTest3 extends JvstTestRoot { { java.lang.reflect.Method m = target.getClass().getMethod(method, new Class[] { int.class, String.class, Object.class }); - Object res = m.invoke(target, new Object[] { new Integer(arg1), arg2, arg3}); + Object res = m.invoke(target, new Object[] { Integer.valueOf(arg1), arg2, arg3}); return ((Integer)res).intValue(); } @@ -1107,7 +1107,7 @@ public class JvstTest3 extends JvstTestRoot { sb.append("}"); ctc.addMethod(CtNewMethod.make(sb.toString(), ctc)); ctc.debugWriteFile(); - ctc.toClass().newInstance(); + ctc.toClass().getConstructor().newInstance(); } // JIRA-83 diff --git a/src/test/javassist/JvstTest4.java b/src/test/javassist/JvstTest4.java index ac4c1e3b..1fdec977 100644 --- a/src/test/javassist/JvstTest4.java +++ b/src/test/javassist/JvstTest4.java @@ -606,7 +606,7 @@ public class JvstTest4 extends JvstTestRoot { pool.makePackage(pool.getClassLoader(), packageName); CtClass ctcl = pool.makeClass("test4.pack.Clazz"); Class cl = ctcl.toClass(); - Object obj = cl.newInstance(); + Object obj = cl.getConstructor().newInstance(); assertEquals(packageName, obj.getClass().getPackage().getName()); } @@ -872,10 +872,17 @@ public class JvstTest4 extends JvstTestRoot { CtClass cc = sloader.get("test4.JIRA181"); CtField field = cc.getField("aField"); String s = field.getAnnotation(test4.JIRA181.Condition.class).toString(); - assertEquals("@test4.JIRA181$Condition(condition=test4.JIRA181<T>.B.class)", s); + if (ClassFile.MAJOR_VERSION < ClassFile.JAVA_9) + assertEquals("@test4.JIRA181$Condition(condition=test4.JIRA181<T>.B.class)", s); + else + assertEquals("@test4.JIRA181$Condition(condition=test4.JIRA181.B.class)", s); + CtField field2 = cc.getField("aField2"); String s2 = field2.getAnnotation(test4.JIRA181.Condition2.class).toString(); - assertEquals("@test4.JIRA181$Condition2(condition=test4.JIRA181<T>.B[].class)", s2); + if (ClassFile.MAJOR_VERSION < ClassFile.JAVA_9) + assertEquals("@test4.JIRA181$Condition2(condition=test4.JIRA181<T>.B[].class)", s2); + else + assertEquals("@test4.JIRA181$Condition2(condition=test4.JIRA181.B[].class)", s2); } public void testJIRA195() throws Exception { @@ -1022,7 +1029,7 @@ public class JvstTest4 extends JvstTestRoot { newClass.debugWriteFile(); Class<?> cClass = newClass.toClass(); - Object o = cClass.newInstance(); + Object o = cClass.getConstructor().newInstance(); java.lang.reflect.Method m = cClass.getMethod("evaluate"); m.invoke(o); m = cClass.getMethod("evaluate2"); diff --git a/src/test/javassist/JvstTest5.java b/src/test/javassist/JvstTest5.java index c20a85f2..26474bb7 100644 --- a/src/test/javassist/JvstTest5.java +++ b/src/test/javassist/JvstTest5.java @@ -77,7 +77,7 @@ public class JvstTest5 extends JvstTestRoot { } public void testJIRA242() throws Exception { - Boolean ss = new Boolean(2 > 3); + Boolean ss = Boolean.valueOf(2 > 3); ClassPool cp = ClassPool.getDefault(); CtClass cc = cp.get("test5.JIRA242$Hello"); CtMethod m = cc.getDeclaredMethod("say"); @@ -219,7 +219,7 @@ public class JvstTest5 extends JvstTestRoot { System.out.println(src); badClass.addMethod(CtMethod.make(src, badClass)); Class clazzz = badClass.toClass(); - Object obj = clazzz.newInstance(); // <-- falls here + Object obj = clazzz.getConstructor().newInstance(); // <-- falls here } public void test83StackmapWithArrayType() throws Exception { @@ -237,6 +237,13 @@ public class JvstTest5 extends JvstTestRoot { 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())); + } + public void testAddDefaultMethod() throws Exception { CtClass cc = sloader.makeInterface("test5.AddDefaultMethod"); cc.addMethod(CtNewMethod.make("static int foo() { return 1; }", cc)); diff --git a/src/test/javassist/JvstTestRoot.java b/src/test/javassist/JvstTestRoot.java index f2dccda3..118e8511 100644 --- a/src/test/javassist/JvstTestRoot.java +++ b/src/test/javassist/JvstTestRoot.java @@ -34,7 +34,7 @@ public class JvstTestRoot extends TestCase { } protected Object make(String name) throws Exception { - return cloader.loadClass(name).newInstance(); + return cloader.loadClass(name).getConstructor().newInstance(); } protected int invoke(Object target, String method) throws Exception { @@ -47,7 +47,7 @@ public class JvstTestRoot extends TestCase { throws Exception { Method m = target.getClass().getMethod(method, new Class[] { int.class }); - Object res = m.invoke(target, new Object[] { new Integer(arg)}); + Object res = m.invoke(target, new Object[] { Integer.valueOf(arg)}); return ((Integer) res).intValue(); } } diff --git a/src/test/javassist/SetterTest.java b/src/test/javassist/SetterTest.java index f11429ad..a989d39a 100644 --- a/src/test/javassist/SetterTest.java +++ b/src/test/javassist/SetterTest.java @@ -29,7 +29,7 @@ public class SetterTest extends TestCase { clazz.addMethod(CtNewMethod.getter("isBroken", field));
Class _class = clazz.toClass();
- Object object = _class.newInstance();
+ Object object = _class.getConstructor().newInstance();
check(_class, object, true);
}
@@ -47,7 +47,7 @@ public class SetterTest extends TestCase { clazz.addMethod(CtNewMethod.setter("setBroken", field));
Class _class = clazz.toClass();
- Object object = _class.newInstance();
+ Object object = _class.getConstructor().newInstance();
set(_class, object, false);
check(_class, object, false);
@@ -67,7 +67,7 @@ public class SetterTest extends TestCase { clazz.addMethod(CtNewMethod.getter("isBroken", field));
Class _class = clazz.toClass();
- Object object = _class.newInstance();
+ Object object = _class.getConstructor().newInstance();
check(_class, object, true);
}
@@ -86,7 +86,7 @@ public class SetterTest extends TestCase { clazz.addMethod(CtNewMethod.setter("setBroken", field));
Class _class = clazz.toClass();
- Object object = _class.newInstance();
+ Object object = _class.getConstructor().newInstance();
set(_class, object, false);
check(_class, object, false);
@@ -106,6 +106,6 @@ public class SetterTest extends TestCase { {
Method method = _class.getMethod("setBroken",
new Class[] {Boolean.TYPE});
- method.invoke(object, new Object[] {new Boolean(willBe)});
+ method.invoke(object, new Object[] { Boolean.valueOf(willBe)});
}
}
diff --git a/src/test/javassist/bytecode/BytecodeTest.java b/src/test/javassist/bytecode/BytecodeTest.java index b918750f..a859f248 100644 --- a/src/test/javassist/bytecode/BytecodeTest.java +++ b/src/test/javassist/bytecode/BytecodeTest.java @@ -29,7 +29,7 @@ public class BytecodeTest extends TestCase { } protected Object make(String name) throws Exception { - return cloader.loadClass(name).newInstance(); + return cloader.loadClass(name).getConstructor().newInstance(); } protected int invoke(Object target, String method) throws Exception { diff --git a/src/test/javassist/bytecode/InsertGap0.java b/src/test/javassist/bytecode/InsertGap0.java index 31fec3aa..6a034141 100644 --- a/src/test/javassist/bytecode/InsertGap0.java +++ b/src/test/javassist/bytecode/InsertGap0.java @@ -175,7 +175,7 @@ public final class InsertGap0 extends JvstTestRoot { Class c = cc.toClass(); cc.stopPruning(p); - Object obj = c.newInstance(); + Object obj = c.getConstructor().newInstance(); assertEquals(2, invoke(obj, "run", 0)); } @@ -194,7 +194,7 @@ public final class InsertGap0 extends JvstTestRoot { Class c = cc.toClass(); cc.stopPruning(p); - Object obj = c.newInstance(); + Object obj = c.getConstructor().newInstance(); assertEquals(0, invoke(obj, "run2", 0)); } diff --git a/src/test/javassist/bytecode/StackMapTest.java b/src/test/javassist/bytecode/StackMapTest.java index fc54c592..77d827be 100644 --- a/src/test/javassist/bytecode/StackMapTest.java +++ b/src/test/javassist/bytecode/StackMapTest.java @@ -37,7 +37,7 @@ public class StackMapTest extends TestCase { } protected Object make(String name) throws Exception { - return cloader.loadClass(name).newInstance(); + return cloader.loadClass(name).getConstructor().newInstance(); } protected int invoke(Object target, String method) throws Exception { @@ -143,7 +143,7 @@ public class StackMapTest extends TestCase { CtClass cc = loader.get("javassist.bytecode.StackMapTest$T1"); rebuildStackMaps2(cc); //Class c = cc.toClass(); - //Object t1 = c.newInstance(); + //Object t1 = c.getConstructor().newInstance(); cc.writeFile(); Object t1 = make(cc.getName()); assertEquals(3, invoke(t1, "test")); @@ -582,9 +582,9 @@ public class StackMapTest extends TestCase { if (v5) // 246: this.print2(s); if (v5) - this.log(ldcw(), v7, s, Long.valueOf(new Integer(i).longValue()), k, null); + this.log(ldcw(), v7, s, Long.valueOf(Integer.valueOf(i).longValue()), k, null); else // 290: - this.log(ldcw(), v7, s, Long.valueOf(new Integer(i).longValue()), k, null); + this.log(ldcw(), v7, s, Long.valueOf(Integer.valueOf(i).longValue()), k, null); return v5; } diff --git a/src/test/javassist/proxyfactory/ProxyFactoryTest.java b/src/test/javassist/proxyfactory/ProxyFactoryTest.java index 5b1bb2ef..2b41af7a 100644 --- a/src/test/javassist/proxyfactory/ProxyFactoryTest.java +++ b/src/test/javassist/proxyfactory/ProxyFactoryTest.java @@ -21,7 +21,7 @@ public class ProxyFactoryTest extends TestCase { MyMethodHandler myHandler = new MyMethodHandler(); myHandler.setX(4711); - MyCls myCls = (MyCls) proxyClass.newInstance(); + MyCls myCls = (MyCls) proxyClass.getConstructor().newInstance(); ((ProxyObject) myCls).setHandler(myHandler); MethodHandler h2 = ((ProxyObject) myCls).getHandler(); @@ -38,7 +38,7 @@ public class ProxyFactoryTest extends TestCase { MyMethodHandler myHandler = new MyMethodHandler(); myHandler.setX(4711); - MyCls myCls = (MyCls) proxyClass.newInstance(); + MyCls myCls = (MyCls) proxyClass.getConstructor().newInstance(); ((ProxyObject) myCls).setHandler(myHandler); @@ -93,21 +93,21 @@ public class ProxyFactoryTest extends TestCase { //proxyFactory.writeDirectory = "./dump"; proxyFactory.setInterfaces(new Class[]{ TestDefaultI.class }); Class intf = proxyFactory.createClass(); - TestDefaultI obj = (TestDefaultI)intf.newInstance(); + TestDefaultI obj = (TestDefaultI)intf.getConstructor().newInstance(); obj.foo(); ProxyFactory proxyFactory2 = new ProxyFactory(); //proxyFactory2.writeDirectory = "./dump"; proxyFactory2.setSuperclass(TestDefaultC.class); Class clazz2 = proxyFactory2.createClass(); - TestDefaultC obj2 = (TestDefaultC)clazz2.newInstance(); + TestDefaultC obj2 = (TestDefaultC)clazz2.getConstructor().newInstance(); obj2.foo(); obj2.bar(); ProxyFactory proxyFactory3 = new ProxyFactory(); proxyFactory3.setSuperclass(TestDefaultC2.class); Class clazz3 = proxyFactory3.createClass(); - TestDefaultC2 obj3 = (TestDefaultC2)clazz3.newInstance(); + TestDefaultC2 obj3 = (TestDefaultC2)clazz3.getConstructor().newInstance(); obj3.foo(); obj3.bar(); obj3.baz(); diff --git a/src/test/javassist/proxyfactory/Tester.java b/src/test/javassist/proxyfactory/Tester.java index 39033885..601076da 100644 --- a/src/test/javassist/proxyfactory/Tester.java +++ b/src/test/javassist/proxyfactory/Tester.java @@ -27,7 +27,7 @@ public class Tester extends TestCase { ProxyFactory f = new ProxyFactory(); f.setSuperclass(Hand.class); Class c = f.createClass(); - Hand foo = (Hand)c.newInstance(); + Hand foo = (Hand)c.getConstructor().newInstance(); ((Proxy)foo).setHandler(mi); assertTrue(ProxyFactory.isProxyClass(c)); assertEquals(3, foo.getHandler()); diff --git a/src/test/test/javassist/bytecode/analysis/ScannerTest.java b/src/test/test/javassist/bytecode/analysis/ScannerTest.java index 10f2936a..56114baf 100644 --- a/src/test/test/javassist/bytecode/analysis/ScannerTest.java +++ b/src/test/test/javassist/bytecode/analysis/ScannerTest.java @@ -72,7 +72,7 @@ public class ScannerTest extends TestCase { assertNotNull(sub); assertEquals(sub.start(), start); for (int i = 0; i < callers.length; i++) - assertTrue(sub.callers().contains(new Integer(callers[i]))); + assertTrue(sub.callers().contains(Integer.valueOf(callers[i]))); } private static void generate(ClassPool pool) throws CannotCompileException, IOException, NotFoundException { diff --git a/src/test/test/javassist/convert/ArrayAccessReplaceTest.java b/src/test/test/javassist/convert/ArrayAccessReplaceTest.java index 09387cec..58ea8357 100644 --- a/src/test/test/javassist/convert/ArrayAccessReplaceTest.java +++ b/src/test/test/javassist/convert/ArrayAccessReplaceTest.java @@ -21,7 +21,7 @@ public class ArrayAccessReplaceTest extends TestCase { converter.replaceArrayAccess(echoClass, new CodeConverter.DefaultArrayAccessReplacementMethodNames()); simpleClass.instrument(converter); //simpleClass.writeFile("/tmp"); - simple = (SimpleInterface) simpleClass.toClass(new URLClassLoader(new URL[0], getClass().getClassLoader()), Class.class.getProtectionDomain()).newInstance(); + simple = (SimpleInterface) simpleClass.toClass(new URLClassLoader(new URL[0], getClass().getClassLoader()), Class.class.getProtectionDomain()).getConstructor().newInstance(); } public void testComplex() throws Exception { @@ -31,8 +31,8 @@ public class ArrayAccessReplaceTest extends TestCase { CodeConverter converter = new CodeConverter(); converter.replaceArrayAccess(clazz, new CodeConverter.DefaultArrayAccessReplacementMethodNames()); clazz.instrument(converter); - ComplexInterface instance = (ComplexInterface) clazz.toClass(new URLClassLoader(new URL[0], getClass().getClassLoader()), Class.class.getProtectionDomain()).newInstance(); - assertEquals(new Integer(5), instance.complexRead(4)); + ComplexInterface instance = (ComplexInterface) clazz.toClass(new URLClassLoader(new URL[0], getClass().getClassLoader()), Class.class.getProtectionDomain()).getConstructor().newInstance(); + assertEquals(Integer.valueOf(5), instance.complexRead(4)); } public void testBoolean() throws Exception { @@ -119,11 +119,11 @@ public class ArrayAccessReplaceTest extends TestCase { public void testObject() throws Exception { for (int i = 0; i < 100; i++) { - simple.setObject(i, new Integer(i)); + simple.setObject(i, Integer.valueOf(i)); } for (int i = 0; i < 100; i++) { - assertEquals(new Integer(i), simple.getObject(i)); + assertEquals(Integer.valueOf(i), simple.getObject(i)); } } @@ -158,67 +158,67 @@ public class ArrayAccessReplaceTest extends TestCase { public static Map shortMap = new HashMap(); public static Object arrayReadObject(Object array, int index) { - return objectMap.get(new Integer(index)); + return objectMap.get(Integer.valueOf(index)); } public static void arrayWriteObject(Object array, int index, Object element) { - objectMap.put(new Integer(index), element); + objectMap.put(Integer.valueOf(index), element); } public static byte arrayReadByteOrBoolean(Object array, int index) { - return ((Byte)byteMap.get(new Integer(index))).byteValue(); + return ((Byte)byteMap.get(Integer.valueOf(index))).byteValue(); } public static void arrayWriteByteOrBoolean(Object array, int index, byte element) { - byteMap.put(new Integer(index), new Byte(element)); + byteMap.put(Integer.valueOf(index), Byte.valueOf(element)); } public static char arrayReadChar(Object array, int index) { - return ((Character)charMap.get(new Integer(index))).charValue(); + return ((Character)charMap.get(Integer.valueOf(index))).charValue(); } public static void arrayWriteChar(Object array, int index, char element) { - charMap.put(new Integer(index), new Character(element)); + charMap.put(Integer.valueOf(index), Character.valueOf(element)); } public static double arrayReadDouble(Object array, int index) { - return ((Double)doubleMap.get(new Integer(index))).doubleValue(); + return ((Double)doubleMap.get(Integer.valueOf(index))).doubleValue(); } public static void arrayWriteDouble(Object array, int index, double element) { - doubleMap.put(new Integer(index), new Double(element)); + doubleMap.put(Integer.valueOf(index), Double.valueOf(element)); } public static float arrayReadFloat(Object array, int index) { - return ((Float)floatMap.get(new Integer(index))).floatValue(); + return ((Float)floatMap.get(Integer.valueOf(index))).floatValue(); } public static void arrayWriteFloat(Object array, int index, float element) { - floatMap.put(new Integer(index), new Float(element)); + floatMap.put(Integer.valueOf(index), Float.valueOf(element)); } public static int arrayReadInt(Object array, int index) { - return ((Integer)intMap.get(new Integer(index))).intValue(); + return ((Integer)intMap.get(Integer.valueOf(index))).intValue(); } public static void arrayWriteInt(Object array, int index, int element) { - intMap.put(new Integer(index), new Integer(element)); + intMap.put(Integer.valueOf(index), Integer.valueOf(element)); } public static long arrayReadLong(Object array, int index) { - return ((Long)longMap.get(new Integer(index))).longValue(); + return ((Long)longMap.get(Integer.valueOf(index))).longValue(); } public static void arrayWriteLong(Object array, int index, long element) { - longMap.put(new Integer(index), new Long(element)); + longMap.put(Integer.valueOf(index), Long.valueOf(element)); } public static short arrayReadShort(Object array, int index) { - return ((Short)shortMap.get(new Integer(index))).shortValue(); + return ((Short)shortMap.get(Integer.valueOf(index))).shortValue(); } public static void arrayWriteShort(Object array, int index, short element) { - shortMap.put(new Integer(index), new Short(element)); + shortMap.put(Integer.valueOf(index), Short.valueOf(element)); } } @@ -393,7 +393,7 @@ public class ArrayAccessReplaceTest extends TestCase { private static Integer justRead; public static Object arrayReadObject(Object array, int offset) { - return new Integer(justRead.intValue() + offset); + return Integer.valueOf(justRead.intValue() + offset); } public static void arrayWriteObject(Object array, int offset, Object element) { @@ -401,7 +401,7 @@ public class ArrayAccessReplaceTest extends TestCase { } public Object getInteger(int i) { - return (Object) new Integer(i); + return (Object) Integer.valueOf(i); } public Number complexRead(int x) { diff --git a/src/test/test/javassist/proxy/JBPAPP9257Test.java b/src/test/test/javassist/proxy/JBPAPP9257Test.java index 2cf2687a..3549f2df 100644 --- a/src/test/test/javassist/proxy/JBPAPP9257Test.java +++ b/src/test/test/javassist/proxy/JBPAPP9257Test.java @@ -27,7 +27,7 @@ public class JBPAPP9257Test extends TestCase { // method. } }; - Foo foo = (Foo)c.newInstance(); + Foo foo = (Foo)c.getConstructor().newInstance(); try { ((ProxyObject)foo).setHandler(mi); fail("foo is a ProxyObject!"); @@ -55,7 +55,7 @@ public class JBPAPP9257Test extends TestCase { // method. } }; - Foo2 foo = (Foo2)c.newInstance(); + Foo2 foo = (Foo2)c.getConstructor().newInstance(); try { ((ProxyObject)foo).setHandler(mi); fail("foo is a ProxyObject!"); diff --git a/src/test/test/javassist/proxy/ProxyCacheGCTest.java b/src/test/test/javassist/proxy/ProxyCacheGCTest.java index 379fefc2..e4331bbd 100644 --- a/src/test/test/javassist/proxy/ProxyCacheGCTest.java +++ b/src/test/test/javassist/proxy/ProxyCacheGCTest.java @@ -93,8 +93,8 @@ public class ProxyCacheGCTest extends TestCase Class javaHandlerClass = classPool.toClass(ctHandlerClass); Class javaFilterClass = classPool.toClass(ctFilterClass); - MethodHandler handler= (MethodHandler)javaHandlerClass.newInstance(); - MethodFilter filter = (MethodFilter)javaFilterClass.newInstance(); + MethodHandler handler= (MethodHandler)javaHandlerClass.getConstructor().newInstance(); + MethodFilter filter = (MethodFilter)javaFilterClass.getConstructor().newInstance(); // ok, now create a factory and a proxy class and proxy from that factory factory.setFilter(filter); @@ -102,7 +102,7 @@ public class ProxyCacheGCTest extends TestCase // factory.setSuperclass(Object.class); Class proxyClass = factory.createClass(); - Object target = proxyClass.newInstance(); + Object target = proxyClass.getConstructor().newInstance(); ((ProxyObject)target).setHandler(handler); } catch (Exception e) { e.printStackTrace(); diff --git a/src/test/test/javassist/proxy/ProxyFactoryCompatibilityTest.java b/src/test/test/javassist/proxy/ProxyFactoryCompatibilityTest.java index 0b255064..634e6c14 100644 --- a/src/test/test/javassist/proxy/ProxyFactoryCompatibilityTest.java +++ b/src/test/test/javassist/proxy/ProxyFactoryCompatibilityTest.java @@ -52,14 +52,14 @@ public class ProxyFactoryCompatibilityTest extends TestCase // create the same class twice and check that it is reused Class proxyClass1 = factory.createClass(); System.out.println("created first class " + proxyClass1.getName()); - TestClass proxy1 = (TestClass)proxyClass1.newInstance(); + TestClass proxy1 = (TestClass)proxyClass1.getConstructor().newInstance(); ((ProxyObject) proxy1).setHandler(handler); proxy1.testMethod(); assertTrue(proxy1.isTestCalled()); Class proxyClass2 = factory.createClass(); System.out.println("created second class " + proxyClass2.getName()); - TestClass proxy2 = (TestClass)proxyClass2.newInstance(); + TestClass proxy2 = (TestClass)proxyClass2.getConstructor().newInstance(); ((ProxyObject) proxy2).setHandler(handler); proxy2.testMethod(); assertTrue(proxy2.isTestCalled()); @@ -76,14 +76,14 @@ public class ProxyFactoryCompatibilityTest extends TestCase // create the same class twice and check that it is reused Class proxyClass3 = factory.createClass(); System.out.println("created third class " + proxyClass3.getName()); - TestClass proxy3 = (TestClass)proxyClass3.newInstance(); + TestClass proxy3 = (TestClass)proxyClass3.getConstructor().newInstance(); ((Proxy)proxy3).setHandler(handler); proxy3.testMethod(); assertTrue(proxy3.isTestCalled()); Class proxyClass4 = factory.createClass(); System.out.println("created fourth class " + proxyClass4.getName()); - TestClass proxy4 = (TestClass)proxyClass4.newInstance(); + TestClass proxy4 = (TestClass)proxyClass4.getConstructor().newInstance(); ((Proxy)proxy4).setHandler(handler); proxy4.testMethod(); assertTrue(proxy4.isTestCalled()); diff --git a/src/test/test/javassist/proxy/ProxySimpleTest.java b/src/test/test/javassist/proxy/ProxySimpleTest.java index 289895cc..42a4f443 100644 --- a/src/test/test/javassist/proxy/ProxySimpleTest.java +++ b/src/test/test/javassist/proxy/ProxySimpleTest.java @@ -35,7 +35,7 @@ public class ProxySimpleTest extends TestCase { return proceed.invoke(self, args); // execute the original method. } }; - Foo foo = (Foo)c.newInstance(); + Foo foo = (Foo)c.getConstructor().newInstance(); ((Proxy)foo).setHandler(mi); testResult = ""; foo.foo(1); @@ -60,7 +60,7 @@ public class ProxySimpleTest extends TestCase { }; ProxyFactory pf = new ProxyFactory(); pf.setSuperclass(ReadWriteData.class); - Object data = pf.createClass().newInstance(); + Object data = pf.createClass().getConstructor().newInstance(); // Object data = new ReadWriteData(); ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(fileName)); oos.writeObject(data); @@ -81,12 +81,12 @@ public class ProxySimpleTest extends TestCase { public void testWriteReplace() throws Exception { ProxyFactory pf = new ProxyFactory(); pf.setSuperclass(WriteReplace.class); - Object data = pf.createClass().newInstance(); + Object data = pf.createClass().getConstructor().newInstance(); assertEquals(data, ((WriteReplace)data).writeReplace()); ProxyFactory pf2 = new ProxyFactory(); pf2.setSuperclass(WriteReplace2.class); - Object data2 = pf2.createClass().newInstance(); + Object data2 = pf2.createClass().getConstructor().newInstance(); Method meth = data2.getClass().getDeclaredMethod("writeReplace", new Class[0]); assertEquals("javassist.util.proxy.SerializedProxy", meth.invoke(data2, new Object[0]).getClass().getName()); @@ -97,7 +97,7 @@ public class ProxySimpleTest extends TestCase { } public static class WriteReplace2 implements Serializable { - public Object writeReplace(int i) { return new Integer(i); } + public Object writeReplace(int i) { return Integer.valueOf(i); } } String value244; @@ -156,7 +156,7 @@ public class ProxySimpleTest extends TestCase { return proceed.invoke(self, args); // execute the original method. } }; - Default3 foo = (Default3)c.newInstance(); + Default3 foo = (Default3)c.getConstructor().newInstance(); ((Proxy)foo).setHandler(mi); foo.foo(); foo.bar(); @@ -176,7 +176,7 @@ public class ProxySimpleTest extends TestCase { return proceed.invoke(self, args); // execute the original method. } }; - Default2 foo = (Default2)c.newInstance(); + Default2 foo = (Default2)c.getConstructor().newInstance(); ((Proxy)foo).setHandler(mi); foo.foo(); foo.bar(); diff --git a/src/test/test2/ConstField.java b/src/test/test2/ConstField.java index d733b4f6..2d08cfc0 100644 --- a/src/test/test2/ConstField.java +++ b/src/test/test2/ConstField.java @@ -8,6 +8,6 @@ public class ConstField { public static final double d = 9.0;
public static final String s = "const";
public static final Object obj = null;
- public static final Integer integer = new Integer(4);
+ public static final Integer integer = Integer.valueOf(4);
public static int k = 2;
}
diff --git a/src/test/test3/Enhancer.java b/src/test/test3/Enhancer.java index 5c9d2a25..8aa13d25 100644 --- a/src/test/test3/Enhancer.java +++ b/src/test/test3/Enhancer.java @@ -35,7 +35,7 @@ public class Enhancer { } }); Class c = e.createClass(); - EnhanceTest obj = (EnhanceTest)c.newInstance(); + EnhanceTest obj = (EnhanceTest)c.getConstructor().newInstance(); obj.foo("test"); } diff --git a/src/test/test4/Signature.java b/src/test/test4/Signature.java index aa9de28b..f6028a1a 100644 --- a/src/test/test4/Signature.java +++ b/src/test/test4/Signature.java @@ -7,7 +7,7 @@ public class Signature<T> { public int run() { Signature<String> s = new Signature<String>(); - return s.foo(new Integer(3), "foo", s, null).length(); + return s.foo(Integer.valueOf(3), "foo", s, null).length(); } <S> T foo(S s, T t, Signature<T> signature, Signature<Signature<String>> v) { diff --git a/src/test/testproxy/ProxyFactoryPerformanceTest.java b/src/test/testproxy/ProxyFactoryPerformanceTest.java index d2081ae2..55bc7849 100644 --- a/src/test/testproxy/ProxyFactoryPerformanceTest.java +++ b/src/test/testproxy/ProxyFactoryPerformanceTest.java @@ -45,7 +45,7 @@ public class ProxyFactoryPerformanceTest extends TestCase { error = null;
Thread[] threads = new Thread[MAX_THREADS];
for (int i = 0; i < threads.length; ++i) {
- threads[i] = (Thread)cl.newInstance();
+ threads[i] = (Thread)cl.getDeclaredConstructor().newInstance();
}
long time = System.currentTimeMillis();
for (int i = 0; i < threads.length; ++i) {
diff --git a/src/test/testproxy/ProxyTester.java b/src/test/testproxy/ProxyTester.java index 77bdfa05..07ae54d2 100644 --- a/src/test/testproxy/ProxyTester.java +++ b/src/test/testproxy/ProxyTester.java @@ -65,7 +65,7 @@ public class ProxyTester extends TestCase { f.setFilter(finalizeRemover);
f.writeDirectory = ".";
Class c = f.createClass();
- Target obj = (Target)c.newInstance();
+ Target obj = (Target)c.getConstructor().newInstance();
((Proxy)obj).setHandler(interceptor);
obj.m();
assertEquals(true, obj.m(true));
@@ -92,7 +92,7 @@ public class ProxyTester extends TestCase { // f.setHandler(interceptor);
f.setFilter(finalizeRemover);
Class c = f.createClass();
- Target1 obj = (Target1)c.newInstance();
+ Target1 obj = (Target1)c.getConstructor().newInstance();
((Proxy)obj).setHandler(interceptor);
assertEquals(null, obj.m(null));
assertEquals(1, interceptor.counter);
@@ -104,7 +104,7 @@ public class ProxyTester extends TestCase { // f.setHandler(interceptor);
f.setFilter(finalizeRemover);
Class c = f.createClass();
- Object obj = (Object)c.newInstance();
+ Object obj = (Object)c.getConstructor().newInstance();
((Proxy)obj).setHandler(interceptor);
System.out.println(obj.toString());
assertEquals(2, interceptor.counter);
@@ -117,7 +117,7 @@ public class ProxyTester extends TestCase { // f.setHandler(interceptor);
f.setFilter(finalizeRemover);
Class c = f.createClass();
- Object obj = (Object)c.newInstance();
+ Object obj = (Object)c.getConstructor().newInstance();
((Proxy)obj).setHandler(interceptor);
System.out.println("setter1: " + obj.toString());
((ProxyObject)obj).setHandler(new MethodHandler() {
@@ -179,7 +179,7 @@ public class ProxyTester extends TestCase { f.setFilter(finalizeRemover);
f.setInterfaces(new Class[] { Target3.class });
Class c = f.createClass();
- Target3 obj = (Target3)c.newInstance();
+ Target3 obj = (Target3)c.getConstructor().newInstance();
((Proxy)obj).setHandler(interceptor2);
assertEquals("OK", obj.m());
System.out.println(obj.toString());
@@ -193,14 +193,14 @@ public class ProxyTester extends TestCase { f.setFilter(finalizeRemover);
f.setInterfaces(new Class[] { Target3.class, Target4.class });
Class c = f.createClass();
- Target3 obj = (Target3)c.newInstance();
+ Target3 obj = (Target3)c.getConstructor().newInstance();
((Proxy)obj).setHandler(interceptor2);
assertEquals("OK", obj.m());
System.out.println(obj.toString());
assertEquals(3, interceptor2.counter);
interceptor2.counter = 0;
- Target4 obj4 = (Target4)c.newInstance();
+ Target4 obj4 = (Target4)c.getConstructor().newInstance();
((Proxy)obj4).setHandler(interceptor2);
assertEquals(3, obj4.bar4());
assertEquals(3, obj4.foo4());
@@ -219,7 +219,7 @@ public class ProxyTester extends TestCase { }
});
Class c = f.createClass();
- Target3 obj = (Target3)c.newInstance();
+ Target3 obj = (Target3)c.getConstructor().newInstance();
((Proxy)obj).setHandler(interceptor2);
assertEquals("OK", obj.m());
System.out.println(obj.toString());
@@ -242,7 +242,7 @@ public class ProxyTester extends TestCase { Class c = f.createClass();
assertTrue(testInitFlag); // since 3.12. Before then, this line was assertFalse(testInitFlag);
System.out.println("testInit createClass(): " + testInitFlag);
- TargetInit obj = (TargetInit)c.newInstance();
+ TargetInit obj = (TargetInit)c.getConstructor().newInstance();
assertTrue(testInitFlag);
System.out.println("testInit newInstance(): " + testInitFlag);
((ProxyObject)obj).setHandler(handler);
@@ -270,7 +270,7 @@ public class ProxyTester extends TestCase { // f.setHandler(interceptor);
f.setFilter(finalizeRemover);
Class c = f.createClass();
- BridgeMethod obj = (BridgeMethod)c.newInstance();
+ BridgeMethod obj = (BridgeMethod)c.getConstructor().newInstance();
((Proxy)obj).setHandler(interceptor);
Integer value = obj.m1();
assertEquals(7, value.intValue());
@@ -370,7 +370,7 @@ public class ProxyTester extends TestCase { };
ProxyFactory pf = new ProxyFactory();
pf.setSuperclass(ReadWriteData.class);
- Object data = pf.createClass().newInstance();
+ Object data = pf.createClass().getConstructor().newInstance();
// Object data = new ReadWriteData();
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(fileName));
oos.writeObject(data);
@@ -391,12 +391,12 @@ public class ProxyTester extends TestCase { public void testWriteReplace() throws Exception {
ProxyFactory pf = new ProxyFactory();
pf.setSuperclass(WriteReplace.class);
- Object data = pf.createClass().newInstance();
+ Object data = pf.createClass().getConstructor().newInstance();
assertEquals(data, ((WriteReplace)data).writeReplace());
ProxyFactory pf2 = new ProxyFactory();
pf2.setSuperclass(WriteReplace2.class);
- Object data2 = pf2.createClass().newInstance();
+ Object data2 = pf2.createClass().getConstructor().newInstance();
Method meth = data2.getClass().getDeclaredMethod("writeReplace", new Class[0]);
assertEquals("javassist.util.proxy.SerializedProxy",
meth.invoke(data2, new Object[0]).getClass().getName());
@@ -407,7 +407,7 @@ public class ProxyTester extends TestCase { }
public static class WriteReplace2 implements Serializable {
- public Object writeReplace(int i) { return new Integer(i); }
+ public Object writeReplace(int i) { return Integer.valueOf(i); }
}
public static void testJIRA189() throws Exception {
@@ -418,7 +418,7 @@ public class ProxyTester extends TestCase { factory.setSuperclass(persistentClass);
factory.setInterfaces(new Class[] { Target189.TestProxy.class });
Class cl = factory.createClass();
- Target189.TestProxy proxy = (Target189.TestProxy)cl.newInstance();
+ Target189.TestProxy proxy = (Target189.TestProxy)cl.getConstructor().newInstance();
Target189.TestMethodHandler methodHandler = new Target189.TestMethodHandler();
((ProxyObject)proxy).setHandler(methodHandler);
((Target189.Article)proxy).getIssue();
|