]> source.dussan.org Git - javassist.git/commitdiff
updates the test code to run on Java 9 EA+149.
authorchibash <chiba@javassist.org>
Tue, 20 Dec 2016 09:07:11 +0000 (18:07 +0900)
committerchibash <chiba@javassist.org>
Tue, 20 Dec 2016 09:07:11 +0000 (18:07 +0900)
Due to the specification change of jigsaw, ClassLoader#defineClass()
cannot be invoked through reflection API.  As a workaround,
  --add-opens java.base/java.lang=ALL-UNNAMED
must be given to the JVM.  The ant target "runtest9" adds this jvm
argument.

build.xml
javassist.jar
src/main/javassist/ClassPoolTail.java
src/test/javassist/JvstTest.java
src/test/javassist/JvstTest2.java
src/test/test/javassist/proxy/ProxySimpleTest.java
src/test/testproxy/ProxyTester.java

index d9c65013bdf1c9be396687c376d2d9315ae1d835..587db2ed13c736b418d4800f24cc6ff53f6c9491 100644 (file)
--- a/build.xml
+++ b/build.xml
 
   <target name="runtest" depends="jar,test-compile">
     <junit fork="true" printsummary="true" dir="${test.run.dir}">
-      <jvmarg value="-XX:-FailOverToOldVerifier" />
+      <jvmarg value="-XX:-FailOverToOldVerifier"/>
+      <classpath refid="test.classpath"/>
+      <formatter type="xml" extension=".xml"/>
+      <test name="javassist.JvstTest" outfile="TestLog" />
+    </junit>
+  </target>
+
+  <target name="runtest9" depends="jar,test-compile">
+    <junit fork="true" printsummary="true" dir="${test.run.dir}">
+      <jvmarg line="--add-opens java.base/java.lang=ALL-UNNAMED" />
+      <jvmarg value="-XX:-FailOverToOldVerifier"/>
       <classpath refid="test.classpath"/>
       <formatter type="xml" extension=".xml"/>
       <test name="javassist.JvstTest" outfile="TestLog" />
index 83712459f2c30305163a9b4ee4e8b288982ba271..5083ca752d31192a1867df36f671489c90252bce 100644 (file)
Binary files a/javassist.jar and b/javassist.jar differ
index 13d22d77ab404dc0ad7edbb0f31d1a9b6df33f08..681c550ea778cd4d3dee3901b25fdaa32f1e08e3 100644 (file)
@@ -241,7 +241,7 @@ final class ClassPoolTail {
 
     public ClassPath appendSystemPath() {
         ClassLoader cl = Thread.currentThread().getContextClassLoader();
-        return appendClassPath(new LoaderClassPath(cl, true));
+        return appendClassPath(new LoaderClassPath(cl));
     }
 
     public ClassPath insertClassPath(String pathname)
index eb57a6433cbb31d6512e792ff972d369a4ec2f1b..550d42785846cf85dc54de97833b0569b0c97355 100644 (file)
@@ -8,8 +8,12 @@ import javassist.expr.*;
 import javassist.runtime.*;
 
 public class JvstTest extends JvstTestRoot {
+    public static boolean java9;
+
     static {
         //javassist.bytecode.MethodInfo.doPreverify = true;
+        java9 = javassist.bytecode.ClassFile.MAJOR_VERSION
+                    >= javassist.bytecode.ClassFile.JAVA_9;
     }
     public JvstTest(String name) {
          super(name);
index 10d5d3e336ccce7b0c2d4d4493cd5fbfbbf2c7fd..443bbb30e95f1659d2c2c53ff07759e499d22e5c 100644 (file)
@@ -295,8 +295,12 @@ public class JvstTest2 extends JvstTestRoot {
 
         url = cp.find("java.lang.Object").toString();
         System.out.println(url);
-        assertTrue(url.startsWith("jar:file:"));
-        assertTrue(url.endsWith(".jar!/java/lang/Object.class"));
+        if (JvstTest.java9)
+            assertEquals("jrt:/java.base/java/lang/Object.class", url);
+        else {
+            assertTrue(url.startsWith("jar:file:"));
+            assertTrue(url.endsWith(".jar!/java/lang/Object.class"));
+        }
 
         assertNull(cp.find("class.not.Exist"));
 
@@ -304,7 +308,7 @@ public class JvstTest2 extends JvstTestRoot {
         cp.insertClassPath(".");
 
         url = cp.find("test2.Inner").toString();
-        System.out.println(url);
+        System.out.println("testURL: " + url);
         assertTrue(url.startsWith("file:/"));
         assertTrue(url.endsWith("/test2/Inner.class"));
 
@@ -314,7 +318,7 @@ public class JvstTest2 extends JvstTestRoot {
         cp.insertClassPath(JAR_PATH + "javassist.jar");
 
         url = cp.find("javassist.CtClass").toString();
-        System.out.println(url);
+        System.out.println("testURL: " + url);
         assertTrue(url.startsWith("jar:file:"));
         assertTrue(url.endsWith("javassist.jar!/javassist/CtClass.class"));
 
@@ -324,9 +328,9 @@ public class JvstTest2 extends JvstTestRoot {
         cp.insertClassPath(new LoaderClassPath(cloader));
 
         url = cp.find("javassist.CtMethod").toString();
-        System.out.println(url);
-        // assertTrue(url.startsWith("jar:file:"));
-        // assertTrue(url.endsWith("javassist.jar!/javassist/CtMethod.class"));
+        System.out.println("testURL: " + url);
+        assertTrue(url.startsWith("file:"));
+        assertTrue(url.endsWith("/javassist/CtMethod.class"));
 
         assertNull(cp.find("javassist.TestURL"));
 
@@ -334,7 +338,7 @@ public class JvstTest2 extends JvstTestRoot {
         cp.insertClassPath(new ByteArrayClassPath("test2.ByteArray", null));
 
         url = cp.find("test2.ByteArray").toString();
-        System.out.println(url);
+        System.out.println("testURL: " + url);
         assertTrue(
             url.equals("file:/ByteArrayClassPath/test2/ByteArray.class"));
 
@@ -361,8 +365,13 @@ public class JvstTest2 extends JvstTestRoot {
         CtClass cc = sloader.get("java.lang.String");
         String url = cc.getURL().toString();
         System.out.println(url);
-        assertTrue(url.startsWith("jar:file:"));
-        assertTrue(url.endsWith(".jar!/java/lang/String.class"));
+        if (JvstTest.java9) {
+            assertEquals("jrt:/java.base/java/lang/String.class", url);
+        }
+        else {
+            assertTrue(url.startsWith("jar:file:"));
+            assertTrue(url.endsWith(".jar!/java/lang/String.class"));
+        }
 
         cc = sloader.get("int");
         try {
index 42a4f443fee49e2f8641ea3fd9e856a64e516cb1..249a25420eafa22df9cb82914d8e5ba46936a116 100644 (file)
@@ -1,6 +1,7 @@
 package test.javassist.proxy;
 
 import junit.framework.TestCase;
+import testproxy.ProxyTester.ReadWriteData;
 
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
@@ -53,19 +54,28 @@ public class ProxySimpleTest extends TestCase {
     public void testReadWrite() throws Exception {
         final String fileName = "read-write.bin";
         ProxyFactory.ClassLoaderProvider cp = ProxyFactory.classLoaderProvider;
-        ProxyFactory.classLoaderProvider = new ProxyFactory.ClassLoaderProvider() {
-            public ClassLoader get(ProxyFactory pf) {
-                return new javassist.Loader();
-            }
-        };
-        ProxyFactory pf = new ProxyFactory();
-        pf.setSuperclass(ReadWriteData.class);
-        Object data = pf.createClass().getConstructor().newInstance();
-        // Object data = new ReadWriteData();
-        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(fileName));
-        oos.writeObject(data);
-        oos.close();
-        ProxyFactory.classLoaderProvider = cp;
+        try {
+            ProxyFactory.classLoaderProvider = new ProxyFactory.ClassLoaderProvider() {
+                public ClassLoader get(ProxyFactory pf) {
+                    /* If javassist.Loader is returned, the super type of ReadWriteData class,
+                     * which is Serializable, is loaded by javassist.Loader as well as ReadWriteData.
+                     * This breaks the implementation of the object serializer.
+                     */
+                    // return new javassist.Loader();
+                    return Thread.currentThread().getContextClassLoader();
+                }
+            };
+            ProxyFactory pf = new ProxyFactory();
+            pf.setSuperclass(ReadWriteData.class);
+            Object data = pf.createClass().getConstructor().newInstance();
+            // Object data = new ReadWriteData();
+            ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(fileName));
+            oos.writeObject(data);
+            oos.close();
+        }
+        finally {
+            ProxyFactory.classLoaderProvider = cp;
+        }
 
         ObjectInputStream ois = new ObjectInputStream(new FileInputStream(fileName));
         Object data2 = ois.readObject();
index 07ae54d27104b0e1ff5e891de718ad195d5539dc..f325997daad5065edbbc639a529141341a43b64a 100644 (file)
-package testproxy;\r
-\r
-import java.lang.reflect.Method;\r
-import java.lang.reflect.Constructor;\r
-import java.lang.reflect.Modifier;\r
-import java.lang.reflect.InvocationTargetException;\r
-import javassist.util.proxy.ProxyFactory;\r
-import javassist.util.proxy.MethodFilter;\r
-import javassist.util.proxy.MethodHandler;\r
-import javassist.util.proxy.ProxyObject;\r
-import javassist.util.proxy.Proxy;\r
-import junit.framework.Assert;\r
-import junit.framework.TestCase;\r
-import java.io.*;\r
-\r
-public class ProxyTester extends TestCase {\r
-    public ProxyTester(String s) {\r
-        super(s);\r
-    }\r
-\r
-    public ProxyTester() {\r
-        this("proxy");\r
-    }\r
-\r
-    static class Interceptor1 implements MethodHandler {\r
-        int counter = 0;\r
-\r
-        public Object invoke(Object self, Method m, Method proceed,\r
-                Object[] args) throws Exception {\r
-            System.out.println("intercept: " + m + ", proceed: " + proceed);\r
-            System.out.println("     modifier: "\r
-                                          + Modifier.toString(proceed.getModifiers()));\r
-            counter++;\r
-            return proceed.invoke(self, args);\r
-        }\r
-    }\r
-\r
-    static class Interceptor2 implements MethodHandler {\r
-        int counter = 0;\r
-        public Object invoke(Object self, Method m, Method proceed,\r
-                             Object[] args) throws Exception {\r
-            System.out.println("intercept: " + m + ", proceed: " + proceed);\r
-            counter++;\r
-            if (proceed != null)\r
-                return proceed.invoke(self, args);\r
-            else\r
-                if (m.getReturnType() == int.class)\r
-                    return Integer.valueOf(3);\r
-                else\r
-                    return "OK";\r
-        }\r
-    }\r
-\r
-    static MethodFilter finalizeRemover = new MethodFilter() {\r
-        public boolean isHandled(Method m) {\r
-            return !m.getName().equals("finalize");\r
-        }\r
-    };\r
-\r
-    public void testTarget() throws Exception {\r
-        ProxyFactory f = new ProxyFactory();\r
-        f.setSuperclass(Target.class);\r
-        Interceptor1 interceptor = new Interceptor1();\r
-        // f.setHandler(interceptor);\r
-        f.setFilter(finalizeRemover);\r
-        f.writeDirectory = ".";\r
-        Class c = f.createClass();\r
-        Target obj = (Target)c.getConstructor().newInstance();\r
-        ((Proxy)obj).setHandler(interceptor);\r
-        obj.m();\r
-        assertEquals(true, obj.m(true));\r
-        assertEquals((byte)1, obj.m1((byte)1));\r
-        assertEquals('a', obj.m2('a'));\r
-        assertEquals((short)2, obj.m3((short)2));\r
-        assertEquals(3, obj.m(3));\r
-        assertEquals(4L, obj.m5(4L));\r
-        assertTrue(5.0F == obj.m6(5.0F));\r
-        assertTrue(6.0 == obj.m7(6.0));\r
-        assertEquals("test", obj.m("test"));\r
-        int[] ia = { 1, 2, 3 };\r
-        assertEquals(ia, obj.m7(ia));\r
-        String[] sa = { "1", "2" };\r
-        assertEquals(sa, obj.m8(sa));\r
-        assertEquals(obj, obj.m9(3, obj, null));\r
-        assertEquals(14, interceptor.counter);\r
-    }\r
-\r
-    public void testTarget1() throws Exception {\r
-        ProxyFactory f = new ProxyFactory();\r
-        f.setSuperclass(Target1.class);\r
-        Interceptor1 interceptor = new Interceptor1();\r
-        // f.setHandler(interceptor);\r
-        f.setFilter(finalizeRemover);\r
-        Class c = f.createClass();\r
-        Target1 obj = (Target1)c.getConstructor().newInstance();\r
-        ((Proxy)obj).setHandler(interceptor);\r
-        assertEquals(null, obj.m(null));\r
-        assertEquals(1, interceptor.counter);\r
-    }\r
-\r
-    public void testObject() throws Exception {\r
-        ProxyFactory f = new ProxyFactory();\r
-        Interceptor1 interceptor = new Interceptor1();\r
-        // f.setHandler(interceptor);\r
-        f.setFilter(finalizeRemover);\r
-        Class c = f.createClass();\r
-        Object obj = (Object)c.getConstructor().newInstance();\r
-        ((Proxy)obj).setHandler(interceptor);\r
-        System.out.println(obj.toString());\r
-        assertEquals(2, interceptor.counter);\r
-    }\r
-\r
-    public void testSetter() throws Exception {\r
-        ProxyFactory f = new ProxyFactory();\r
-        f.writeDirectory = ".";\r
-        Interceptor1 interceptor = new Interceptor1();\r
-        // f.setHandler(interceptor);\r
-        f.setFilter(finalizeRemover);\r
-        Class c = f.createClass();\r
-        Object obj = (Object)c.getConstructor().newInstance();\r
-        ((Proxy)obj).setHandler(interceptor);\r
-        System.out.println("setter1: " + obj.toString());\r
-        ((ProxyObject)obj).setHandler(new MethodHandler() {\r
-            public Object invoke(Object self, Method m, Method proceed,\r
-                    Object[] args) throws Exception {\r
-                System.out.print("intercept: " + m);\r
-                return "OK";\r
-            }\r
-        });\r
-        assertEquals("OK", obj.toString());\r
-    }\r
-\r
-    public void testString() throws Exception {\r
-        ProxyFactory f = new ProxyFactory();\r
-        Interceptor1 interceptor = new Interceptor1();\r
-        // f.setHandler(interceptor);\r
-        f.setFilter(finalizeRemover);\r
-        f.setSuperclass(String.class);\r
-        try {\r
-            Class c = f.createClass();\r
-            Assert.fail("String is final!");\r
-        }\r
-        catch (RuntimeException e) {\r
-            System.out.println(e);\r
-        }\r
-    }\r
-\r
-    public void testConstructor() throws Exception {\r
-        ProxyFactory f = new ProxyFactory();\r
-        Interceptor1 interceptor = new Interceptor1();\r
-        // f.setHandler(interceptor);\r
-        f.setFilter(finalizeRemover);\r
-        f.setSuperclass(Target2.class);\r
-        Class c = f.createClass();\r
-        Constructor[] cons = c.getDeclaredConstructors();\r
-        assertEquals(3, cons.length);\r
-        Constructor con1 = c.getDeclaredConstructor(new Class[] { int.class });\r
-        Constructor con2 = c.getDeclaredConstructor(new Class[] { int.class, int.class });\r
-        Method m1 = c.getDeclaredMethod("get", new Class[0]);\r
-        Method m2 = c.getDeclaredMethod("foo", new Class[0]);\r
-        assertEquals(0, m1.getExceptionTypes().length);\r
-        assertEquals("java.io.IOException", m2.getExceptionTypes()[0].getName());\r
-\r
-        Target2 t2 = (Target2)con1.newInstance(new Object[] { Integer.valueOf(1) });\r
-        ((Proxy)t2).setHandler(interceptor);\r
-        System.out.println(t2.toString());\r
-        assertEquals(2, interceptor.counter);\r
-\r
-        interceptor.counter = 0;\r
-        assertEquals(2, t2.foo());\r
-        assertEquals(4, t2._dfoo());\r
-        assertEquals(2, interceptor.counter);\r
-    }\r
-\r
-    public void testInterface() throws Exception {\r
-        ProxyFactory f = new ProxyFactory();\r
-        Interceptor2 interceptor2 = new Interceptor2();\r
-        // f.setHandler(interceptor2);\r
-        f.setFilter(finalizeRemover);\r
-        f.setInterfaces(new Class[] { Target3.class });\r
-        Class c = f.createClass();\r
-        Target3 obj = (Target3)c.getConstructor().newInstance();\r
-        ((Proxy)obj).setHandler(interceptor2);\r
-        assertEquals("OK", obj.m());\r
-        System.out.println(obj.toString());\r
-        assertEquals(3, interceptor2.counter);\r
-    }\r
-\r
-    public void test2Interfaces() throws Exception {\r
-        ProxyFactory f = new ProxyFactory();\r
-        Interceptor2 interceptor2 = new Interceptor2();\r
-        // f.setHandler(interceptor2);\r
-        f.setFilter(finalizeRemover);\r
-        f.setInterfaces(new Class[] { Target3.class, Target4.class });\r
-        Class c = f.createClass();\r
-        Target3 obj = (Target3)c.getConstructor().newInstance();\r
-        ((Proxy)obj).setHandler(interceptor2);\r
-        assertEquals("OK", obj.m());\r
-        System.out.println(obj.toString());\r
-        assertEquals(3, interceptor2.counter);\r
-\r
-        interceptor2.counter = 0;\r
-        Target4 obj4 = (Target4)c.getConstructor().newInstance();\r
-        ((Proxy)obj4).setHandler(interceptor2);\r
-        assertEquals(3, obj4.bar4());\r
-        assertEquals(3, obj4.foo4());\r
-        assertEquals(2, interceptor2.counter);\r
-    }\r
-\r
-    public void testFilter() throws Exception {\r
-        ProxyFactory f = new ProxyFactory();\r
-        Interceptor2 interceptor2 = new Interceptor2();\r
-        // f.setHandler(interceptor2);\r
-        f.setFilter(finalizeRemover);\r
-        f.setInterfaces(new Class[] { Target3.class });\r
-        f.setFilter(new MethodFilter() {\r
-                public boolean isHandled(Method m) {\r
-                    return m.getDeclaringClass() != Object.class;\r
-                }\r
-            });\r
-        Class c = f.createClass();\r
-        Target3 obj = (Target3)c.getConstructor().newInstance();\r
-        ((Proxy)obj).setHandler(interceptor2);\r
-        assertEquals("OK", obj.m());\r
-        System.out.println(obj.toString());\r
-        assertEquals(1, interceptor2.counter);\r
-    }\r
-\r
-    public static boolean testInitFlag;\r
-\r
-    public void testInit() throws Exception {\r
-        ProxyFactory f = new ProxyFactory();\r
-        f.setSuperclass(TargetInit.class);\r
-        MethodHandler handler = new MethodHandler() {\r
-            public Object invoke(Object self, Method m,\r
-                    Method proceed, Object[] args) throws Exception {\r
-                System.out.println("testInit " + testInitFlag);\r
-                return proceed.invoke(self, args);\r
-            }\r
-        };\r
-        testInitFlag = false;\r
-        Class c = f.createClass();\r
-        assertTrue(testInitFlag); // since 3.12.  Before then, this line was assertFalse(testInitFlag);\r
-        System.out.println("testInit createClass(): " + testInitFlag);\r
-        TargetInit obj = (TargetInit)c.getConstructor().newInstance();\r
-        assertTrue(testInitFlag);\r
-        System.out.println("testInit newInstance(): " + testInitFlag);\r
-        ((ProxyObject)obj).setHandler(handler);\r
-        assertEquals("OK", obj.m());\r
-    }\r
-\r
-    public void testCreate() throws Exception {\r
-        ProxyFactory f = new ProxyFactory();\r
-        f.setSuperclass(Target5.class);\r
-        Interceptor1 interceptor = new Interceptor1();\r
-        // f.setHandler(interceptor);\r
-        f.setFilter(finalizeRemover);\r
-        Class c = f.createClass();\r
-        Target5 obj = (Target5)f.create(new Class[] { int.class }, new Object[] { Integer.valueOf(3) });\r
-        ((Proxy)obj).setHandler(interceptor);\r
-        assertEquals(3, obj.get());\r
-    }\r
-\r
-\r
-    public void testBridgeMethod() throws Exception {\r
-        ProxyFactory f = new ProxyFactory();\r
-        f.writeDirectory = ".";\r
-        f.setSuperclass(BridgeMethod.class);\r
-        Interceptor1 interceptor = new Interceptor1();\r
-        // f.setHandler(interceptor);\r
-        f.setFilter(finalizeRemover);\r
-        Class c = f.createClass();\r
-        BridgeMethod obj = (BridgeMethod)c.getConstructor().newInstance();\r
-        ((Proxy)obj).setHandler(interceptor);\r
-        Integer value = obj.m1();\r
-        assertEquals(7, value.intValue());\r
-        BridgeMethodInf inf = (BridgeMethodInf)obj;\r
-        Number num = inf.m1();\r
-        assertEquals(7, num.intValue());\r
-        BridgeMethodSuper sup = obj;\r
-        try {\r
-            Object x = sup.id(new Object());\r
-            fail("not cast error");\r
-        }\r
-        catch (ClassCastException e) {}\r
-        catch (Exception e) {\r
-            if (e instanceof InvocationTargetException)\r
-                if (e.getCause() instanceof ClassCastException)\r
-                    return;\r
-\r
-            throw e;\r
-        }\r
-    }\r
-\r
-    public void testGetters() throws Exception {\r
-        ProxyFactory f = new ProxyFactory();\r
-        Class c = ProxyTester.class;\r
-        f.setSuperclass(c);\r
-        assertEquals(c, f.getSuperclass());\r
-        Class i = java.io.Serializable.class;\r
-        f.setInterfaces(new Class[] { i });\r
-        assertEquals(i, f.getInterfaces()[0]);\r
-    }\r
-\r
-    static class ProxyFactory2 extends ProxyFactory {\r
-        public ClassLoader getClassLoader2() {\r
-            return getClassLoader();\r
-        }\r
-    }\r
-\r
-    public void testProvider() throws Exception {\r
-        ProxyFactory.ClassLoaderProvider cp = ProxyFactory.classLoaderProvider;\r
-        final ClassLoader cl = Thread.currentThread().getContextClassLoader();\r
-        ProxyFactory.classLoaderProvider = new ProxyFactory.ClassLoaderProvider() {\r
-            public ClassLoader get(ProxyFactory pf) {\r
-                return Thread.currentThread().getContextClassLoader();\r
-            }\r
-        };\r
-\r
-        ProxyFactory2 pf = new ProxyFactory2();\r
-        assertEquals(cl, pf.getClassLoader2());\r
-        ProxyFactory.classLoaderProvider = cp;\r
-    }\r
-\r
-    @SuppressWarnings("deprecation")\r
-       public void testCache() throws Exception {\r
-        boolean prev = ProxyFactory.useCache;\r
-        ProxyFactory.useCache = true;\r
-        ProxyFactory f = new ProxyFactory();\r
-        f.setSuperclass(Cache1.class);\r
-        Class c = f.createClass();\r
-        ProxyFactory f2 = new ProxyFactory();\r
-        f2.setSuperclass(Cache1.class);\r
-        assertEquals(c, f2.createClass());\r
-        ProxyFactory f3 = new ProxyFactory();\r
-        f3.setSuperclass(Cache1.class);\r
-        f3.setHandler(new Interceptor1());     // deprecated\r
-        assertFalse(c == f3.createClass());\r
-        ProxyFactory.useCache = true;\r
-        ProxyFactory f4 = new ProxyFactory();\r
-        f4.setSuperclass(Cache1.class);\r
-        f4.setInterfaces(new Class[] { Cache2.class });\r
-        Class c4 = f4.createClass();\r
-        assertFalse(c == c4);\r
-        ProxyFactory f5 = new ProxyFactory();\r
-        f5.setSuperclass(Cache1.class);\r
-        f5.setInterfaces(new Class[] { Cache2.class });\r
-        assertEquals(c4, f5.createClass());\r
-        ProxyFactory f6 = new ProxyFactory();\r
-        f6.setInterfaces(new Class[] { Cache2.class });\r
-        assertFalse(c4 == f6.createClass());\r
-        ProxyFactory.useCache = prev;\r
-    }\r
-\r
-    public static class Cache1 {\r
-        public int foo() { return 0; }\r
-    }\r
-\r
-    public static interface Cache2 {\r
-        public int bar();\r
-    }\r
-\r
-    public void testReadWrite() throws Exception {\r
-        final String fileName = "read-write.bin";\r
-        ProxyFactory.ClassLoaderProvider cp = ProxyFactory.classLoaderProvider;\r
-        ProxyFactory.classLoaderProvider = new ProxyFactory.ClassLoaderProvider() {\r
-            public ClassLoader get(ProxyFactory pf) {\r
-                return new javassist.Loader();\r
-            }\r
-        };\r
-        ProxyFactory pf = new ProxyFactory();\r
-        pf.setSuperclass(ReadWriteData.class);\r
-        Object data = pf.createClass().getConstructor().newInstance();\r
-        // Object data = new ReadWriteData();\r
-        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(fileName));\r
-        oos.writeObject(data);\r
-        oos.close();\r
-        ProxyFactory.classLoaderProvider = cp;\r
-\r
-        ObjectInputStream ois = new ObjectInputStream(new FileInputStream(fileName));\r
-        Object data2 = ois.readObject();\r
-        ois.close();\r
-        int i = ((ReadWriteData)data2).foo();\r
-        assertEquals(4, i);\r
-    }\r
-\r
-    public static class ReadWriteData implements Serializable {\r
-        public int foo() { return 4; }\r
-    }\r
-\r
-    public void testWriteReplace() throws Exception {\r
-        ProxyFactory pf = new ProxyFactory();\r
-        pf.setSuperclass(WriteReplace.class);\r
-        Object data = pf.createClass().getConstructor().newInstance();\r
-        assertEquals(data, ((WriteReplace)data).writeReplace());\r
-\r
-        ProxyFactory pf2 = new ProxyFactory();\r
-        pf2.setSuperclass(WriteReplace2.class);\r
-        Object data2 = pf2.createClass().getConstructor().newInstance();\r
-        Method meth = data2.getClass().getDeclaredMethod("writeReplace", new Class[0]);\r
-        assertEquals("javassist.util.proxy.SerializedProxy",\r
-                    meth.invoke(data2, new Object[0]).getClass().getName());\r
-    }\r
-\r
-    public static class WriteReplace implements Serializable {\r
-        public Object writeReplace() { return this; }\r
-    }\r
-\r
-    public static class WriteReplace2 implements Serializable {\r
-        public Object writeReplace(int i) { return Integer.valueOf(i); }\r
-    }\r
-\r
-    public static void testJIRA189() throws Exception {\r
-       Class persistentClass = Target189.PublishedArticle.class;\r
-        ProxyFactory factory = new ProxyFactory();\r
-        // factory.writeDirectory = ".";\r
-        factory.setUseCache(false);\r
-        factory.setSuperclass(persistentClass);\r
-        factory.setInterfaces(new Class[] { Target189.TestProxy.class });\r
-        Class cl = factory.createClass();\r
-        Target189.TestProxy proxy = (Target189.TestProxy)cl.getConstructor().newInstance();\r
-        Target189.TestMethodHandler methodHandler = new Target189.TestMethodHandler();\r
-        ((ProxyObject)proxy).setHandler(methodHandler);\r
-        ((Target189.Article)proxy).getIssue();\r
-        assertTrue(methodHandler.wasInvokedOnce());\r
-        methodHandler.reset();\r
-        Target189.PublishedArticle article = (Target189.PublishedArticle)proxy;\r
-        article.getIssue();\r
-        assertTrue(methodHandler.wasInvokedOnce());\r
-    }\r
-\r
-    public void testJIRA127() throws Exception {\r
-        ProxyFactory proxyFactory = new ProxyFactory();\r
-        // proxyFactory.writeDirectory = ".";\r
-        proxyFactory.setInterfaces(new Class[]{ Target127.Sub.class });\r
-        Target127.Sub proxy = (Target127.Sub)proxyFactory.create(new Class[0], new Object[0], new MethodHandler() {\r
-            public Object invoke(Object self, Method thisMethod, Method proceed, Object[] args) throws Throwable {\r
-                return null;\r
-            }\r
-        });\r
-        ((Target127.Super)proxy).item();    // proxyFactory must generate a bridge method.\r
-        ((Target127.Sub)proxy).item();\r
-    }\r
-\r
-    public static void main(String[] args) {\r
-        // javassist.bytecode.ClassFile.MAJOR_VERSION = javassist.bytecode.ClassFile.JAVA_6;\r
-        junit.textui.TestRunner.run(ProxyTester.class);\r
-    }\r
-}\r
+package testproxy;
+
+import java.lang.reflect.Method;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Modifier;
+import java.lang.reflect.InvocationTargetException;
+import javassist.util.proxy.ProxyFactory;
+import javassist.util.proxy.MethodFilter;
+import javassist.util.proxy.MethodHandler;
+import javassist.util.proxy.ProxyObject;
+import javassist.util.proxy.Proxy;
+import junit.framework.Assert;
+import junit.framework.TestCase;
+import java.io.*;
+
+public class ProxyTester extends TestCase {
+    public ProxyTester(String s) {
+        super(s);
+    }
+
+    public ProxyTester() {
+        this("proxy");
+    }
+
+    static class Interceptor1 implements MethodHandler {
+        int counter = 0;
+
+        public Object invoke(Object self, Method m, Method proceed,
+                Object[] args) throws Exception {
+            System.out.println("intercept: " + m + ", proceed: " + proceed);
+            System.out.println("     modifier: "
+                               + Modifier.toString(proceed.getModifiers()));
+            counter++;
+            return proceed.invoke(self, args);
+        }
+    }
+
+    static class Interceptor2 implements MethodHandler {
+        int counter = 0;
+        public Object invoke(Object self, Method m, Method proceed,
+                             Object[] args) throws Exception {
+            System.out.println("intercept: " + m + ", proceed: " + proceed);
+            counter++;
+            if (proceed != null)
+                return proceed.invoke(self, args);
+            else
+                if (m.getReturnType() == int.class)
+                    return Integer.valueOf(3);
+                else
+                    return "OK";
+        }
+    }
+
+    static MethodFilter finalizeRemover = new MethodFilter() {
+        public boolean isHandled(Method m) {
+            return !m.getName().equals("finalize");
+        }
+    };
+
+    public void testTarget() throws Exception {
+        ProxyFactory f = new ProxyFactory();
+        f.setSuperclass(Target.class);
+        Interceptor1 interceptor = new Interceptor1();
+        // f.setHandler(interceptor);
+        f.setFilter(finalizeRemover);
+        f.writeDirectory = ".";
+        Class c = f.createClass();
+        Target obj = (Target)c.getConstructor().newInstance();
+        ((Proxy)obj).setHandler(interceptor);
+        obj.m();
+        assertEquals(true, obj.m(true));
+        assertEquals((byte)1, obj.m1((byte)1));
+        assertEquals('a', obj.m2('a'));
+        assertEquals((short)2, obj.m3((short)2));
+        assertEquals(3, obj.m(3));
+        assertEquals(4L, obj.m5(4L));
+        assertTrue(5.0F == obj.m6(5.0F));
+        assertTrue(6.0 == obj.m7(6.0));
+        assertEquals("test", obj.m("test"));
+        int[] ia = { 1, 2, 3 };
+        assertEquals(ia, obj.m7(ia));
+        String[] sa = { "1", "2" };
+        assertEquals(sa, obj.m8(sa));
+        assertEquals(obj, obj.m9(3, obj, null));
+        assertEquals(14, interceptor.counter);
+    }
+
+    public void testTarget1() throws Exception {
+        ProxyFactory f = new ProxyFactory();
+        f.setSuperclass(Target1.class);
+        Interceptor1 interceptor = new Interceptor1();
+        // f.setHandler(interceptor);
+        f.setFilter(finalizeRemover);
+        Class c = f.createClass();
+        Target1 obj = (Target1)c.getConstructor().newInstance();
+        ((Proxy)obj).setHandler(interceptor);
+        assertEquals(null, obj.m(null));
+        assertEquals(1, interceptor.counter);
+    }
+
+    public void testObject() throws Exception {
+        ProxyFactory f = new ProxyFactory();
+        Interceptor1 interceptor = new Interceptor1();
+        // f.setHandler(interceptor);
+        f.setFilter(finalizeRemover);
+        Class c = f.createClass();
+        Object obj = (Object)c.getConstructor().newInstance();
+        ((Proxy)obj).setHandler(interceptor);
+        System.out.println(obj.toString());
+        assertEquals(2, interceptor.counter);
+    }
+
+    public void testSetter() throws Exception {
+        ProxyFactory f = new ProxyFactory();
+        f.writeDirectory = ".";
+        Interceptor1 interceptor = new Interceptor1();
+        // f.setHandler(interceptor);
+        f.setFilter(finalizeRemover);
+        Class c = f.createClass();
+        Object obj = (Object)c.getConstructor().newInstance();
+        ((Proxy)obj).setHandler(interceptor);
+        System.out.println("setter1: " + obj.toString());
+        ((ProxyObject)obj).setHandler(new MethodHandler() {
+            public Object invoke(Object self, Method m, Method proceed,
+                    Object[] args) throws Exception {
+                System.out.print("intercept: " + m);
+                return "OK";
+            }
+        });
+        assertEquals("OK", obj.toString());
+    }
+
+    public void testString() throws Exception {
+        ProxyFactory f = new ProxyFactory();
+        Interceptor1 interceptor = new Interceptor1();
+        // f.setHandler(interceptor);
+        f.setFilter(finalizeRemover);
+        f.setSuperclass(String.class);
+        try {
+            Class c = f.createClass();
+            Assert.fail("String is final!");
+        }
+        catch (RuntimeException e) {
+            System.out.println(e);
+        }
+    }
+
+    public void testConstructor() throws Exception {
+        ProxyFactory f = new ProxyFactory();
+        Interceptor1 interceptor = new Interceptor1();
+        // f.setHandler(interceptor);
+        f.setFilter(finalizeRemover);
+        f.setSuperclass(Target2.class);
+        Class c = f.createClass();
+        Constructor[] cons = c.getDeclaredConstructors();
+        assertEquals(3, cons.length);
+        Constructor con1 = c.getDeclaredConstructor(new Class[] { int.class });
+        Constructor con2 = c.getDeclaredConstructor(new Class[] { int.class, int.class });
+        Method m1 = c.getDeclaredMethod("get", new Class[0]);
+        Method m2 = c.getDeclaredMethod("foo", new Class[0]);
+        assertEquals(0, m1.getExceptionTypes().length);
+        assertEquals("java.io.IOException", m2.getExceptionTypes()[0].getName());
+
+        Target2 t2 = (Target2)con1.newInstance(new Object[] { Integer.valueOf(1) });
+        ((Proxy)t2).setHandler(interceptor);
+        System.out.println(t2.toString());
+        assertEquals(2, interceptor.counter);
+
+        interceptor.counter = 0;
+        assertEquals(2, t2.foo());
+        assertEquals(4, t2._dfoo());
+        assertEquals(2, interceptor.counter);
+    }
+
+    public void testInterface() throws Exception {
+        ProxyFactory f = new ProxyFactory();
+        Interceptor2 interceptor2 = new Interceptor2();
+        // f.setHandler(interceptor2);
+        f.setFilter(finalizeRemover);
+        f.setInterfaces(new Class[] { Target3.class });
+        Class c = f.createClass();
+        Target3 obj = (Target3)c.getConstructor().newInstance();
+        ((Proxy)obj).setHandler(interceptor2);
+        assertEquals("OK", obj.m());
+        System.out.println(obj.toString());
+        assertEquals(3, interceptor2.counter);
+    }
+
+    public void test2Interfaces() throws Exception {
+        ProxyFactory f = new ProxyFactory();
+        Interceptor2 interceptor2 = new Interceptor2();
+        // f.setHandler(interceptor2);
+        f.setFilter(finalizeRemover);
+        f.setInterfaces(new Class[] { Target3.class, Target4.class });
+        Class c = f.createClass();
+        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.getConstructor().newInstance();
+        ((Proxy)obj4).setHandler(interceptor2);
+        assertEquals(3, obj4.bar4());
+        assertEquals(3, obj4.foo4());
+        assertEquals(2, interceptor2.counter);
+    }
+
+    public void testFilter() throws Exception {
+        ProxyFactory f = new ProxyFactory();
+        Interceptor2 interceptor2 = new Interceptor2();
+        // f.setHandler(interceptor2);
+        f.setFilter(finalizeRemover);
+        f.setInterfaces(new Class[] { Target3.class });
+        f.setFilter(new MethodFilter() {
+                public boolean isHandled(Method m) {
+                    return m.getDeclaringClass() != Object.class;
+                }
+            });
+        Class c = f.createClass();
+        Target3 obj = (Target3)c.getConstructor().newInstance();
+        ((Proxy)obj).setHandler(interceptor2);
+        assertEquals("OK", obj.m());
+        System.out.println(obj.toString());
+        assertEquals(1, interceptor2.counter);
+    }
+
+    public static boolean testInitFlag;
+
+    public void testInit() throws Exception {
+        ProxyFactory f = new ProxyFactory();
+        f.setSuperclass(TargetInit.class);
+        MethodHandler handler = new MethodHandler() {
+            public Object invoke(Object self, Method m,
+                    Method proceed, Object[] args) throws Exception {
+                System.out.println("testInit " + testInitFlag);
+                return proceed.invoke(self, args);
+            }
+        };
+        testInitFlag = false;
+        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.getConstructor().newInstance();
+        assertTrue(testInitFlag);
+        System.out.println("testInit newInstance(): " + testInitFlag);
+        ((ProxyObject)obj).setHandler(handler);
+        assertEquals("OK", obj.m());
+    }
+
+    public void testCreate() throws Exception {
+        ProxyFactory f = new ProxyFactory();
+        f.setSuperclass(Target5.class);
+        Interceptor1 interceptor = new Interceptor1();
+        // f.setHandler(interceptor);
+        f.setFilter(finalizeRemover);
+        Class c = f.createClass();
+        Target5 obj = (Target5)f.create(new Class[] { int.class }, new Object[] { Integer.valueOf(3) });
+        ((Proxy)obj).setHandler(interceptor);
+        assertEquals(3, obj.get());
+    }
+
+
+    public void testBridgeMethod() throws Exception {
+        ProxyFactory f = new ProxyFactory();
+        f.writeDirectory = ".";
+        f.setSuperclass(BridgeMethod.class);
+        Interceptor1 interceptor = new Interceptor1();
+        // f.setHandler(interceptor);
+        f.setFilter(finalizeRemover);
+        Class c = f.createClass();
+        BridgeMethod obj = (BridgeMethod)c.getConstructor().newInstance();
+        ((Proxy)obj).setHandler(interceptor);
+        Integer value = obj.m1();
+        assertEquals(7, value.intValue());
+        BridgeMethodInf inf = (BridgeMethodInf)obj;
+        Number num = inf.m1();
+        assertEquals(7, num.intValue());
+        BridgeMethodSuper sup = obj;
+        try {
+            Object x = sup.id(new Object());
+            fail("not cast error");
+        }
+        catch (ClassCastException e) {}
+        catch (Exception e) {
+            if (e instanceof InvocationTargetException)
+                if (e.getCause() instanceof ClassCastException)
+                    return;
+
+            throw e;
+        }
+    }
+
+    public void testGetters() throws Exception {
+        ProxyFactory f = new ProxyFactory();
+        Class c = ProxyTester.class;
+        f.setSuperclass(c);
+        assertEquals(c, f.getSuperclass());
+        Class i = java.io.Serializable.class;
+        f.setInterfaces(new Class[] { i });
+        assertEquals(i, f.getInterfaces()[0]);
+    }
+
+    static class ProxyFactory2 extends ProxyFactory {
+        public ClassLoader getClassLoader2() {
+            return getClassLoader();
+        }
+    }
+
+    public void testProvider() throws Exception {
+        ProxyFactory.ClassLoaderProvider cp = ProxyFactory.classLoaderProvider;
+        try {
+            final ClassLoader cl = Thread.currentThread().getContextClassLoader();
+            ProxyFactory.classLoaderProvider = new ProxyFactory.ClassLoaderProvider() {
+                public ClassLoader get(ProxyFactory pf) {
+                    return Thread.currentThread().getContextClassLoader();
+                }
+            };
+
+            ProxyFactory2 pf = new ProxyFactory2();
+            assertEquals(cl, pf.getClassLoader2());
+        }
+        finally {
+            ProxyFactory.classLoaderProvider = cp;
+        }
+    }
+
+    @SuppressWarnings("deprecation")
+       public void testCache() throws Exception {
+        boolean prev = ProxyFactory.useCache;
+        ProxyFactory.useCache = true;
+        ProxyFactory f = new ProxyFactory();
+        f.setSuperclass(Cache1.class);
+        Class c = f.createClass();
+        ProxyFactory f2 = new ProxyFactory();
+        f2.setSuperclass(Cache1.class);
+        assertEquals(c, f2.createClass());
+        ProxyFactory f3 = new ProxyFactory();
+        f3.setSuperclass(Cache1.class);
+        f3.setHandler(new Interceptor1());     // deprecated
+        assertFalse(c == f3.createClass());
+        ProxyFactory.useCache = true;
+        ProxyFactory f4 = new ProxyFactory();
+        f4.setSuperclass(Cache1.class);
+        f4.setInterfaces(new Class[] { Cache2.class });
+        Class c4 = f4.createClass();
+        assertFalse(c == c4);
+        ProxyFactory f5 = new ProxyFactory();
+        f5.setSuperclass(Cache1.class);
+        f5.setInterfaces(new Class[] { Cache2.class });
+        assertEquals(c4, f5.createClass());
+        ProxyFactory f6 = new ProxyFactory();
+        f6.setInterfaces(new Class[] { Cache2.class });
+        assertFalse(c4 == f6.createClass());
+        ProxyFactory.useCache = prev;
+    }
+
+    public static class Cache1 {
+        public int foo() { return 0; }
+    }
+
+    public static interface Cache2 {
+        public int bar();
+    }
+
+    public void testReadWrite() throws Exception {
+        final String fileName = "read-write.bin";
+        ProxyFactory.ClassLoaderProvider cp = ProxyFactory.classLoaderProvider;
+        try {
+            ProxyFactory.classLoaderProvider = new ProxyFactory.ClassLoaderProvider() {
+                public ClassLoader get(ProxyFactory pf) {
+                    /* If javassist.Loader is returned, the super type of ReadWriteData class,
+                     * which is Serializable, is loaded by javassist.Loader as well as ReadWriteData.
+                     * This breaks the implementation of the object serializer.
+                     */
+                    // return new javassist.Loader();
+                    return Thread.currentThread().getContextClassLoader();
+                }
+            };
+            ProxyFactory pf = new ProxyFactory();
+            pf.setSuperclass(ReadWriteData.class);
+            Object data = pf.createClass().getConstructor().newInstance();
+            //Object data = new ReadWriteData();
+            ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(fileName));
+            oos.writeObject(data);
+            oos.close();
+        }
+        finally {
+            ProxyFactory.classLoaderProvider = cp;
+        }
+
+        ObjectInputStream ois = new ObjectInputStream(new FileInputStream(fileName));
+        Object data2 = ois.readObject();
+        ois.close();
+        int i = ((ReadWriteData)data2).foo();
+        assertEquals(4, i);
+    }
+
+    public static class ReadWriteData implements Serializable {
+        public int foo() { return 4; }
+    }
+
+    public void testWriteReplace() throws Exception {
+        ProxyFactory pf = new ProxyFactory();
+        pf.setSuperclass(WriteReplace.class);
+        Object data = pf.createClass().getConstructor().newInstance();
+        assertEquals(data, ((WriteReplace)data).writeReplace());
+
+        ProxyFactory pf2 = new ProxyFactory();
+        pf2.setSuperclass(WriteReplace2.class);
+        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());
+    }
+
+    public static class WriteReplace implements Serializable {
+        public Object writeReplace() { return this; }
+    }
+
+    public static class WriteReplace2 implements Serializable {
+        public Object writeReplace(int i) { return Integer.valueOf(i); }
+    }
+
+    public static void testJIRA189() throws Exception {
+        Class persistentClass = Target189.PublishedArticle.class;
+        ProxyFactory factory = new ProxyFactory();
+        //factory.writeDirectory = ".";
+        factory.setUseCache(false);
+        factory.setSuperclass(persistentClass);
+        factory.setInterfaces(new Class[] { Target189.TestProxy.class });
+        Class cl = factory.createClass();
+        Object obj = cl.getConstructor().newInstance();
+        System.out.println("JIRA189:" + obj.getClass().getClassLoader() + ", " + obj.getClass().getSuperclass().getName()
+                            + ", " + Target189.PublishedArticle.class.getClassLoader());
+        Target189.TestProxy proxy = (Target189.TestProxy)cl.getConstructor().newInstance();
+        Target189.TestMethodHandler methodHandler = new Target189.TestMethodHandler();
+        ((ProxyObject)proxy).setHandler(methodHandler);
+        ((Target189.Article)proxy).getIssue();
+        assertTrue(methodHandler.wasInvokedOnce());
+        methodHandler.reset();
+        Target189.PublishedArticle article = (Target189.PublishedArticle)proxy;
+        article.getIssue();
+        assertTrue(methodHandler.wasInvokedOnce());
+    }
+
+    public void testJIRA127() throws Exception {
+        ProxyFactory proxyFactory = new ProxyFactory();
+        // proxyFactory.writeDirectory = ".";
+        proxyFactory.setInterfaces(new Class[]{ Target127.Sub.class });
+        Target127.Sub proxy = (Target127.Sub)proxyFactory.create(new Class[0], new Object[0], new MethodHandler() {
+            public Object invoke(Object self, Method thisMethod, Method proceed, Object[] args) throws Throwable {
+                return null;
+            }
+        });
+        ((Target127.Super)proxy).item();    // proxyFactory must generate a bridge method.
+        ((Target127.Sub)proxy).item();
+    }
+
+    public static void main(String[] args) {
+        // javassist.bytecode.ClassFile.MAJOR_VERSION = javassist.bytecode.ClassFile.JAVA_6;
+        junit.textui.TestRunner.run(ProxyTester.class);
+    }
+}