]> source.dussan.org Git - javassist.git/commitdiff
fixes many compatibility problems with older Java (i.e. 1.4) 88/head
authorchibash <chiba@javassist.org>
Thu, 14 Jul 2016 14:36:15 +0000 (23:36 +0900)
committerchibash <chiba@javassist.org>
Thu, 14 Jul 2016 14:36:15 +0000 (23:36 +0900)
Readme.html
build.xml
javassist.jar [deleted file]
src/main/javassist/tools/Callback.java
src/test/javassist/JvstTest.java
src/test/javassist/JvstTest2.java
src/test/test/javassist/proxy/ProxyFactoryCompatibilityTest.java
src/test/testproxy/ProxyFactoryPerformanceTest.java
src/test/testproxy/ProxyTester.java

index 7290c099a95f3baf678f5b8985d862ef5caba3b5..3015f7adcb67e8401e03ff6e78a37c227bc8d03b 100644 (file)
@@ -284,6 +284,8 @@ see javassist.Dump.
 <p>-version 3.21
 <ul>
 <li>JIRA JASSIST-244, 245, 248, 250, 255, 256, 259, 262.
+<li><code>javassist.tools.Callback</code> was modified to be Java 1.4 compatible.
+The parameter type of <code>Callback#result()</code> was changed.
 </ul>
 </p>
 
index b22829e09df3eb44e9b3649d5fad93875a3654dd..a4a6034a2653c5b683324e06941284e7f4aaf005 100644 (file)
--- a/build.xml
+++ b/build.xml
@@ -64,6 +64,7 @@
            debug="on"
            deprecation="on"
            optimize="off"
+          includeantruntime="true"
            includes="**">
             <classpath refid="classpath"/>
     </javac>
@@ -77,6 +78,7 @@
               source="1.6"
               target="1.6"
            optimize="off"
+          includeantruntime="true"
            includes="**">
       <classpath refid="classpath"/>
     </javac>
@@ -88,6 +90,7 @@
            debug="on"
            deprecation="on"
            optimize="off"
+          includeantruntime="false"
            includes="**">
             <classpath refid="test.compile.classpath"/>
             <compilerarg value="-parameters" />        
diff --git a/javassist.jar b/javassist.jar
deleted file mode 100644 (file)
index bcc617c..0000000
Binary files a/javassist.jar and /dev/null differ
index 56c874146ac7592bbfee5953914d15955ccd6435..c3095ccb1e580d1c05fb9ff72756fa7bb5ea308d 100644 (file)
@@ -28,7 +28,7 @@ import java.util.UUID;
  * <p>Example of how to create and insert a callback:</p>
  * <pre>
  * ctMethod.insertAfter(new Callback("Thread.currentThread()") {
- *     public void result(Object... objects) {
+ *     public void result(Object[] objects) {
  *         Thread thread = (Thread) objects[0];
  *         // do something with thread...
  *     }
@@ -37,7 +37,7 @@ import java.util.UUID;
  * <p>Contains utility methods for inserts callbacks in <code>CtBehaviour</code>, example:</p>
  * <pre>
  * insertAfter(ctBehaviour, new Callback("Thread.currentThread(), dummyString") {
- *     public void result(Object... objects) {
+ *     public void result(Object[] objects) {
  *         Thread thread = (Thread) objects[0];
  *         // do something with thread...
  *     }
@@ -45,10 +45,11 @@ import java.util.UUID;
  * </pre>
  *
  * @author Marten Hedborg
+ * @author Shigeru Chiba
  */
 public abstract class Callback {
 
-    public static HashMap<String, Callback> callbacks = new HashMap<String, Callback>();
+    public static HashMap callbacks = new HashMap();
 
     private final String sourceCode;
 
@@ -70,9 +71,8 @@ public abstract class Callback {
      *
      * @param objects   Objects that the bytecode in callback returns
      */
-    public abstract void result(Object... objects);
+    public abstract void result(Object[] objects);
 
-    @Override
     public String toString(){
         return sourceCode();
     }
index 791b0820e0ca3ad4f04e363e76211475d9d5fb0d..9a671de67e2640e3fcc0a1b1ddeead9831ba4bbd 100644 (file)
@@ -842,7 +842,7 @@ public class JvstTest extends JvstTestRoot {
         // cloader.loadClass(cc.getName());
         java.io.File genDir = new java.io.File(".");
         java.net.URLClassLoader ucl = new java.net.URLClassLoader(
-                        new java.net.URL[] { genDir.toURL() }, null);
+                        new java.net.URL[] { genDir.toURI().toURL() }, null);
         Class intf = ucl.loadClass("test1.MkInterface");
     }
 
index 411c1e97e0d053f4f3f982acfd182957e79ba70e..4ff84784e3e0b28c25cd03a1932cf623c537aa02 100644 (file)
@@ -516,15 +516,15 @@ public class JvstTest2 extends JvstTestRoot {
         CtClass out = sloader.get("test2.Anon");
         CtClass inner = sloader.get("test2.Anon$1");
         if (System.getProperty("java.vm.version").startsWith("1.4"))
-            assertTrue(inner.getEnclosingMethod() == null);
+            assertTrue(inner.getEnclosingBehavior() == null);
         else {
-            assertEquals("make", inner.getEnclosingMethod().getName());
+            assertEquals("make", inner.getEnclosingBehavior().getName());
             assertEquals(out, inner.getDeclaringClass());
             assertEquals(out,
-                         inner.getEnclosingMethod().getDeclaringClass());
+                         inner.getEnclosingBehavior().getDeclaringClass());
         }
 
-        assertNull(out.getEnclosingMethod());
+        assertNull(out.getEnclosingBehavior());
         assertNull(out.getEnclosingBehavior());
 
         CtClass inner2 = sloader.get("test2.Anon$Anon2$1");
index 5b72d82e1475222588591ebef806ec61391f3db9..0b255064e842c7226803159c1ed2edf3b18f9b3a 100644 (file)
@@ -3,6 +3,7 @@ package test.javassist.proxy;
 import javassist.*;
 import javassist.util.proxy.MethodFilter;
 import javassist.util.proxy.MethodHandler;
+import javassist.util.proxy.Proxy;
 import javassist.util.proxy.ProxyFactory;
 import javassist.util.proxy.ProxyObject;
 import junit.framework.TestCase;
@@ -71,22 +72,23 @@ public class ProxyFactoryCompatibilityTest extends TestCase
         factory.setSuperclass(TestClass.class);
         factory.setInterfaces(new Class[] { TestInterface.class});
         factory.setFilter(filter);
-        factory.setHandler(handler);
 
         // 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();
+        ((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();
+        ((Proxy)proxy4).setHandler(handler);
         proxy4.testMethod();
         assertTrue(proxy4.isTestCalled());
 
-        assertTrue(proxyClass3 != proxyClass4);
+        assertTrue(proxyClass3 == proxyClass4);
     }
 
     /**
index 5ce0adb68717e4050e191dca083ca19b17a77c06..d2081ae2057be2106655ddf0aa63f1d062182a4c 100644 (file)
@@ -104,7 +104,7 @@ class ProxyMaker extends Thread implements MethodHandler {
                        factory.setSuperclass(SampleBean.class);\r
                        factory.setInterfaces(SampleBean.class.getInterfaces());\r
                        factory.setFilter(FINALIZE_FILTER);\r
-                       factory.setHandler(this);\r
+                       // factory.setHandler(this);\r
 \r
                        Class proxyClass = factory.createClass();\r
                        //System.out.println("proxy name: " + proxyClass.getName());\r
index e06848f822b9ab01d99e7e62ed11da34ea40739d..77bdfa059dae019d9e4b19bc431aeadc317da4ff 100644 (file)
@@ -8,6 +8,7 @@ import javassist.util.proxy.ProxyFactory;
 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
@@ -44,7 +45,7 @@ public class ProxyTester extends TestCase {
                 return proceed.invoke(self, args);\r
             else\r
                 if (m.getReturnType() == int.class)\r
-                    return new Integer(3);\r
+                    return Integer.valueOf(3);\r
                 else\r
                     return "OK";\r
         }\r
@@ -60,11 +61,12 @@ public class ProxyTester extends TestCase {
         ProxyFactory f = new ProxyFactory();\r
         f.setSuperclass(Target.class);\r
         Interceptor1 interceptor = new Interceptor1();\r
-        f.setHandler(interceptor);\r
+        // f.setHandler(interceptor);\r
         f.setFilter(finalizeRemover);\r
         f.writeDirectory = ".";\r
         Class c = f.createClass();\r
         Target obj = (Target)c.newInstance();\r
+        ((Proxy)obj).setHandler(interceptor);\r
         obj.m();\r
         assertEquals(true, obj.m(true));\r
         assertEquals((byte)1, obj.m1((byte)1));\r
@@ -87,10 +89,11 @@ public class ProxyTester extends TestCase {
         ProxyFactory f = new ProxyFactory();\r
         f.setSuperclass(Target1.class);\r
         Interceptor1 interceptor = new Interceptor1();\r
-        f.setHandler(interceptor);\r
+        // f.setHandler(interceptor);\r
         f.setFilter(finalizeRemover);\r
         Class c = f.createClass();\r
         Target1 obj = (Target1)c.newInstance();\r
+        ((Proxy)obj).setHandler(interceptor);\r
         assertEquals(null, obj.m(null));\r
         assertEquals(1, interceptor.counter);\r
     }\r
@@ -98,10 +101,11 @@ public class ProxyTester extends TestCase {
     public void testObject() throws Exception {\r
         ProxyFactory f = new ProxyFactory();\r
         Interceptor1 interceptor = new Interceptor1();\r
-        f.setHandler(interceptor);\r
+        // f.setHandler(interceptor);\r
         f.setFilter(finalizeRemover);\r
         Class c = f.createClass();\r
         Object obj = (Object)c.newInstance();\r
+        ((Proxy)obj).setHandler(interceptor);\r
         System.out.println(obj.toString());\r
         assertEquals(2, interceptor.counter);\r
     }\r
@@ -110,10 +114,11 @@ public class ProxyTester extends TestCase {
         ProxyFactory f = new ProxyFactory();\r
         f.writeDirectory = ".";\r
         Interceptor1 interceptor = new Interceptor1();\r
-        f.setHandler(interceptor);\r
+        // f.setHandler(interceptor);\r
         f.setFilter(finalizeRemover);\r
         Class c = f.createClass();\r
         Object obj = (Object)c.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
@@ -128,7 +133,7 @@ public class ProxyTester extends TestCase {
     public void testString() throws Exception {\r
         ProxyFactory f = new ProxyFactory();\r
         Interceptor1 interceptor = new Interceptor1();\r
-        f.setHandler(interceptor);\r
+        // f.setHandler(interceptor);\r
         f.setFilter(finalizeRemover);\r
         f.setSuperclass(String.class);\r
         try {\r
@@ -143,7 +148,7 @@ public class ProxyTester extends TestCase {
     public void testConstructor() throws Exception {\r
         ProxyFactory f = new ProxyFactory();\r
         Interceptor1 interceptor = new Interceptor1();\r
-        f.setHandler(interceptor);\r
+        // f.setHandler(interceptor);\r
         f.setFilter(finalizeRemover);\r
         f.setSuperclass(Target2.class);\r
         Class c = f.createClass();\r
@@ -156,7 +161,8 @@ public class ProxyTester extends TestCase {
         assertEquals(0, m1.getExceptionTypes().length);\r
         assertEquals("java.io.IOException", m2.getExceptionTypes()[0].getName());\r
 \r
-        Target2 t2 = (Target2)con1.newInstance(new Object[] { new Integer(1) });\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
@@ -169,11 +175,12 @@ public class ProxyTester extends TestCase {
     public void testInterface() throws Exception {\r
         ProxyFactory f = new ProxyFactory();\r
         Interceptor2 interceptor2 = new Interceptor2();\r
-        f.setHandler(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.newInstance();\r
+        ((Proxy)obj).setHandler(interceptor2);\r
         assertEquals("OK", obj.m());\r
         System.out.println(obj.toString());\r
         assertEquals(3, interceptor2.counter);\r
@@ -182,17 +189,19 @@ public class ProxyTester extends TestCase {
     public void test2Interfaces() throws Exception {\r
         ProxyFactory f = new ProxyFactory();\r
         Interceptor2 interceptor2 = new Interceptor2();\r
-        f.setHandler(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.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.newInstance();\r
+        ((Proxy)obj4).setHandler(interceptor2);\r
         assertEquals(3, obj4.bar4());\r
         assertEquals(3, obj4.foo4());\r
         assertEquals(2, interceptor2.counter);\r
@@ -201,7 +210,7 @@ public class ProxyTester extends TestCase {
     public void testFilter() throws Exception {\r
         ProxyFactory f = new ProxyFactory();\r
         Interceptor2 interceptor2 = new Interceptor2();\r
-        f.setHandler(interceptor2);\r
+        // f.setHandler(interceptor2);\r
         f.setFilter(finalizeRemover);\r
         f.setInterfaces(new Class[] { Target3.class });\r
         f.setFilter(new MethodFilter() {\r
@@ -211,6 +220,7 @@ public class ProxyTester extends TestCase {
             });\r
         Class c = f.createClass();\r
         Target3 obj = (Target3)c.newInstance();\r
+        ((Proxy)obj).setHandler(interceptor2);\r
         assertEquals("OK", obj.m());\r
         System.out.println(obj.toString());\r
         assertEquals(1, interceptor2.counter);\r
@@ -243,10 +253,11 @@ public class ProxyTester extends TestCase {
         ProxyFactory f = new ProxyFactory();\r
         f.setSuperclass(Target5.class);\r
         Interceptor1 interceptor = new Interceptor1();\r
-        f.setHandler(interceptor);\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[] { new Integer(3) });\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
@@ -256,10 +267,11 @@ public class ProxyTester extends TestCase {
         f.writeDirectory = ".";\r
         f.setSuperclass(BridgeMethod.class);\r
         Interceptor1 interceptor = new Interceptor1();\r
-        f.setHandler(interceptor);\r
+        // f.setHandler(interceptor);\r
         f.setFilter(finalizeRemover);\r
         Class c = f.createClass();\r
         BridgeMethod obj = (BridgeMethod)c.newInstance();\r
+        ((Proxy)obj).setHandler(interceptor);\r
         Integer value = obj.m1();\r
         assertEquals(7, value.intValue());\r
         BridgeMethodInf inf = (BridgeMethodInf)obj;\r
@@ -310,7 +322,8 @@ public class ProxyTester extends TestCase {
         ProxyFactory.classLoaderProvider = cp;\r
     }\r
 \r
-    public void testCache() throws Exception {\r
+    @SuppressWarnings("deprecation")\r
+       public void testCache() throws Exception {\r
         boolean prev = ProxyFactory.useCache;\r
         ProxyFactory.useCache = true;\r
         ProxyFactory f = new ProxyFactory();\r
@@ -321,8 +334,9 @@ public class ProxyTester extends TestCase {
         assertEquals(c, f2.createClass());\r
         ProxyFactory f3 = new ProxyFactory();\r
         f3.setSuperclass(Cache1.class);\r
-        f3.setHandler(new Interceptor1());\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