diff options
-rw-r--r-- | Readme.html | 2 | ||||
-rw-r--r-- | build.xml | 3 | ||||
-rw-r--r-- | javassist.jar | bin | 721634 -> 0 bytes | |||
-rw-r--r-- | src/main/javassist/tools/Callback.java | 10 | ||||
-rw-r--r-- | src/test/javassist/JvstTest.java | 2 | ||||
-rw-r--r-- | src/test/javassist/JvstTest2.java | 8 | ||||
-rw-r--r-- | src/test/test/javassist/proxy/ProxyFactoryCompatibilityTest.java | 6 | ||||
-rw-r--r-- | src/test/testproxy/ProxyFactoryPerformanceTest.java | 2 | ||||
-rw-r--r-- | src/test/testproxy/ProxyTester.java | 46 |
9 files changed, 50 insertions, 29 deletions
diff --git a/Readme.html b/Readme.html index 7290c099..3015f7ad 100644 --- a/Readme.html +++ b/Readme.html @@ -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> @@ -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 Binary files differdeleted file mode 100644 index bcc617c6..00000000 --- a/javassist.jar +++ /dev/null diff --git a/src/main/javassist/tools/Callback.java b/src/main/javassist/tools/Callback.java index 56c87414..c3095ccb 100644 --- a/src/main/javassist/tools/Callback.java +++ b/src/main/javassist/tools/Callback.java @@ -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(); } diff --git a/src/test/javassist/JvstTest.java b/src/test/javassist/JvstTest.java index 791b0820..9a671de6 100644 --- a/src/test/javassist/JvstTest.java +++ b/src/test/javassist/JvstTest.java @@ -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"); } diff --git a/src/test/javassist/JvstTest2.java b/src/test/javassist/JvstTest2.java index 411c1e97..4ff84784 100644 --- a/src/test/javassist/JvstTest2.java +++ b/src/test/javassist/JvstTest2.java @@ -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"); diff --git a/src/test/test/javassist/proxy/ProxyFactoryCompatibilityTest.java b/src/test/test/javassist/proxy/ProxyFactoryCompatibilityTest.java index 5b72d82e..0b255064 100644 --- a/src/test/test/javassist/proxy/ProxyFactoryCompatibilityTest.java +++ b/src/test/test/javassist/proxy/ProxyFactoryCompatibilityTest.java @@ -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); } /** diff --git a/src/test/testproxy/ProxyFactoryPerformanceTest.java b/src/test/testproxy/ProxyFactoryPerformanceTest.java index 5ce0adb6..d2081ae2 100644 --- a/src/test/testproxy/ProxyFactoryPerformanceTest.java +++ b/src/test/testproxy/ProxyFactoryPerformanceTest.java @@ -104,7 +104,7 @@ class ProxyMaker extends Thread implements MethodHandler { factory.setSuperclass(SampleBean.class);
factory.setInterfaces(SampleBean.class.getInterfaces());
factory.setFilter(FINALIZE_FILTER);
- factory.setHandler(this);
+ // factory.setHandler(this);
Class proxyClass = factory.createClass();
//System.out.println("proxy name: " + proxyClass.getName());
diff --git a/src/test/testproxy/ProxyTester.java b/src/test/testproxy/ProxyTester.java index e06848f8..77bdfa05 100644 --- a/src/test/testproxy/ProxyTester.java +++ b/src/test/testproxy/ProxyTester.java @@ -8,6 +8,7 @@ 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.*;
@@ -44,7 +45,7 @@ public class ProxyTester extends TestCase { return proceed.invoke(self, args);
else
if (m.getReturnType() == int.class)
- return new Integer(3);
+ return Integer.valueOf(3);
else
return "OK";
}
@@ -60,11 +61,12 @@ public class ProxyTester extends TestCase { ProxyFactory f = new ProxyFactory();
f.setSuperclass(Target.class);
Interceptor1 interceptor = new Interceptor1();
- f.setHandler(interceptor);
+ // f.setHandler(interceptor);
f.setFilter(finalizeRemover);
f.writeDirectory = ".";
Class c = f.createClass();
Target obj = (Target)c.newInstance();
+ ((Proxy)obj).setHandler(interceptor);
obj.m();
assertEquals(true, obj.m(true));
assertEquals((byte)1, obj.m1((byte)1));
@@ -87,10 +89,11 @@ public class ProxyTester extends TestCase { ProxyFactory f = new ProxyFactory();
f.setSuperclass(Target1.class);
Interceptor1 interceptor = new Interceptor1();
- f.setHandler(interceptor);
+ // f.setHandler(interceptor);
f.setFilter(finalizeRemover);
Class c = f.createClass();
Target1 obj = (Target1)c.newInstance();
+ ((Proxy)obj).setHandler(interceptor);
assertEquals(null, obj.m(null));
assertEquals(1, interceptor.counter);
}
@@ -98,10 +101,11 @@ public class ProxyTester extends TestCase { public void testObject() throws Exception {
ProxyFactory f = new ProxyFactory();
Interceptor1 interceptor = new Interceptor1();
- f.setHandler(interceptor);
+ // f.setHandler(interceptor);
f.setFilter(finalizeRemover);
Class c = f.createClass();
Object obj = (Object)c.newInstance();
+ ((Proxy)obj).setHandler(interceptor);
System.out.println(obj.toString());
assertEquals(2, interceptor.counter);
}
@@ -110,10 +114,11 @@ public class ProxyTester extends TestCase { ProxyFactory f = new ProxyFactory();
f.writeDirectory = ".";
Interceptor1 interceptor = new Interceptor1();
- f.setHandler(interceptor);
+ // f.setHandler(interceptor);
f.setFilter(finalizeRemover);
Class c = f.createClass();
Object obj = (Object)c.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,
@@ -128,7 +133,7 @@ public class ProxyTester extends TestCase { public void testString() throws Exception {
ProxyFactory f = new ProxyFactory();
Interceptor1 interceptor = new Interceptor1();
- f.setHandler(interceptor);
+ // f.setHandler(interceptor);
f.setFilter(finalizeRemover);
f.setSuperclass(String.class);
try {
@@ -143,7 +148,7 @@ public class ProxyTester extends TestCase { public void testConstructor() throws Exception {
ProxyFactory f = new ProxyFactory();
Interceptor1 interceptor = new Interceptor1();
- f.setHandler(interceptor);
+ // f.setHandler(interceptor);
f.setFilter(finalizeRemover);
f.setSuperclass(Target2.class);
Class c = f.createClass();
@@ -156,7 +161,8 @@ public class ProxyTester extends TestCase { assertEquals(0, m1.getExceptionTypes().length);
assertEquals("java.io.IOException", m2.getExceptionTypes()[0].getName());
- Target2 t2 = (Target2)con1.newInstance(new Object[] { new Integer(1) });
+ Target2 t2 = (Target2)con1.newInstance(new Object[] { Integer.valueOf(1) });
+ ((Proxy)t2).setHandler(interceptor);
System.out.println(t2.toString());
assertEquals(2, interceptor.counter);
@@ -169,11 +175,12 @@ public class ProxyTester extends TestCase { public void testInterface() throws Exception {
ProxyFactory f = new ProxyFactory();
Interceptor2 interceptor2 = new Interceptor2();
- f.setHandler(interceptor2);
+ // f.setHandler(interceptor2);
f.setFilter(finalizeRemover);
f.setInterfaces(new Class[] { Target3.class });
Class c = f.createClass();
Target3 obj = (Target3)c.newInstance();
+ ((Proxy)obj).setHandler(interceptor2);
assertEquals("OK", obj.m());
System.out.println(obj.toString());
assertEquals(3, interceptor2.counter);
@@ -182,17 +189,19 @@ public class ProxyTester extends TestCase { public void test2Interfaces() throws Exception {
ProxyFactory f = new ProxyFactory();
Interceptor2 interceptor2 = new Interceptor2();
- f.setHandler(interceptor2);
+ // f.setHandler(interceptor2);
f.setFilter(finalizeRemover);
f.setInterfaces(new Class[] { Target3.class, Target4.class });
Class c = f.createClass();
Target3 obj = (Target3)c.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();
+ ((Proxy)obj4).setHandler(interceptor2);
assertEquals(3, obj4.bar4());
assertEquals(3, obj4.foo4());
assertEquals(2, interceptor2.counter);
@@ -201,7 +210,7 @@ public class ProxyTester extends TestCase { public void testFilter() throws Exception {
ProxyFactory f = new ProxyFactory();
Interceptor2 interceptor2 = new Interceptor2();
- f.setHandler(interceptor2);
+ // f.setHandler(interceptor2);
f.setFilter(finalizeRemover);
f.setInterfaces(new Class[] { Target3.class });
f.setFilter(new MethodFilter() {
@@ -211,6 +220,7 @@ public class ProxyTester extends TestCase { });
Class c = f.createClass();
Target3 obj = (Target3)c.newInstance();
+ ((Proxy)obj).setHandler(interceptor2);
assertEquals("OK", obj.m());
System.out.println(obj.toString());
assertEquals(1, interceptor2.counter);
@@ -243,10 +253,11 @@ public class ProxyTester extends TestCase { ProxyFactory f = new ProxyFactory();
f.setSuperclass(Target5.class);
Interceptor1 interceptor = new Interceptor1();
- f.setHandler(interceptor);
+ // f.setHandler(interceptor);
f.setFilter(finalizeRemover);
Class c = f.createClass();
- Target5 obj = (Target5)f.create(new Class[] { int.class }, new Object[] { new Integer(3) });
+ Target5 obj = (Target5)f.create(new Class[] { int.class }, new Object[] { Integer.valueOf(3) });
+ ((Proxy)obj).setHandler(interceptor);
assertEquals(3, obj.get());
}
@@ -256,10 +267,11 @@ public class ProxyTester extends TestCase { f.writeDirectory = ".";
f.setSuperclass(BridgeMethod.class);
Interceptor1 interceptor = new Interceptor1();
- f.setHandler(interceptor);
+ // f.setHandler(interceptor);
f.setFilter(finalizeRemover);
Class c = f.createClass();
BridgeMethod obj = (BridgeMethod)c.newInstance();
+ ((Proxy)obj).setHandler(interceptor);
Integer value = obj.m1();
assertEquals(7, value.intValue());
BridgeMethodInf inf = (BridgeMethodInf)obj;
@@ -310,7 +322,8 @@ public class ProxyTester extends TestCase { ProxyFactory.classLoaderProvider = cp;
}
- public void testCache() throws Exception {
+ @SuppressWarnings("deprecation")
+ public void testCache() throws Exception {
boolean prev = ProxyFactory.useCache;
ProxyFactory.useCache = true;
ProxyFactory f = new ProxyFactory();
@@ -321,8 +334,9 @@ public class ProxyTester extends TestCase { assertEquals(c, f2.createClass());
ProxyFactory f3 = new ProxyFactory();
f3.setSuperclass(Cache1.class);
- f3.setHandler(new Interceptor1());
+ 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 });
|