diff of cglib software
-- [Keith has just fallen down a hole] "Here's the top of a ladder. Why didn't you use it?" "I was unable to on account of falling past" [Malicia & Keith] (Terry Prathcett, Amazing Maurice)
diff --git a/src/proxy/net/sf/cglib/core/DefaultNamingPolicy.java b/src/proxy/net/sf/cglib/core/DefaultNamingPolicy.java index 110e921..8485d1a 100644 --- a/src/proxy/net/sf/cglib/core/DefaultNamingPolicy.java +++ b/src/proxy/net/sf/cglib/core/DefaultNamingPolicy.java @@ -55,4 +55,12 @@ public class DefaultNamingPolicy implements NamingPolicy { protected String getTag() { return "ByCGLIB"; } + + public int hashCode() { + return getTag().hashCode(); + } + + public boolean equals(Object o) { + return (o instanceof DefaultNamingPolicy) && ((DefaultNamingPolicy) o).getTag().equals(getTag()); + } } diff --git a/src/proxy/net/sf/cglib/core/ReflectUtils.java b/src/proxy/net/sf/cglib/core/ReflectUtils.java index ec5e268..c2e7f32 100644 --- a/src/proxy/net/sf/cglib/core/ReflectUtils.java +++ b/src/proxy/net/sf/cglib/core/ReflectUtils.java @@ -25,7 +25,7 @@ import org.objectweb.asm.Attribute; import org.objectweb.asm.Type; /** - * @version $Id: ReflectUtils.java,v 1.29 2006/02/28 00:30:51 herbyderby Exp $ + * @version $Id: ReflectUtils.java,v 1.30 2009/01/11 19:47:49 herbyderby Exp $ */ public class ReflectUtils { private ReflectUtils() { } @@ -381,7 +381,10 @@ public class ReflectUtils { public static Class defineClass(String className, byte[] b, ClassLoader loader) throws Exception { Object[] args = new Object[]{className, b, new Integer(0), new Integer(b.length), PROTECTION_DOMAIN }; - return (Class)DEFINE_CLASS.invoke(loader, args); + Class c = (Class)DEFINE_CLASS.invoke(loader, args); + // Force static initializers to run. + Class.forName(className, true, loader); + return c; } public static int findPackageProtected(Class[] classes) { diff --git a/src/proxy/net/sf/cglib/proxy/MethodProxy.java b/src/proxy/net/sf/cglib/proxy/MethodProxy.java index 72d8a4b..8b5725d 100644 --- a/src/proxy/net/sf/cglib/proxy/MethodProxy.java +++ b/src/proxy/net/sf/cglib/proxy/MethodProxy.java @@ -30,7 +30,7 @@ import net.sf.cglib.reflect.FastClass; * registered {@link MethodInterceptor} objects when an intercepted method is invoked. It can * be used to either invoke the original method, or call the same method on a different * object of the same type. - * @version $Id: MethodProxy.java,v 1.14 2008/05/26 04:05:50 herbyderby Exp $ + * @version $Id: MethodProxy.java,v 1.15 2009/01/11 19:47:49 herbyderby Exp $ */ public class MethodProxy { private Signature sig1; @@ -73,9 +73,12 @@ public class MethodProxy { FastClassInfo fci = new FastClassInfo(); fci.f1 = helper(ci, ci.c1); fci.f2 = helper(ci, ci.c2); + System.err.println("gen f1: " + fci.f1.getClass()); + System.err.println("gen f2: " + fci.f2.getClass()); fci.i1 = fci.f1.getIndex(sig1); fci.i2 = fci.f2.getIndex(sig2); fastClassInfo = fci; + createInfo = null; } } } @@ -104,6 +107,7 @@ public class MethodProxy { AbstractClassGenerator fromEnhancer = AbstractClassGenerator.getCurrent(); if (fromEnhancer != null) { namingPolicy = fromEnhancer.getNamingPolicy(); + System.err.println("from enhancer: " + namingPolicy); strategy = fromEnhancer.getStrategy(); attemptLoad = fromEnhancer.getAttemptLoad(); } @@ -152,6 +156,18 @@ public class MethodProxy { return fastClassInfo.i2; } + // For testing + FastClass getFastClass() { + init(); + return fastClassInfo.f1; + } + + // For testing + FastClass getSuperFastClass() { + init(); + return fastClassInfo.f2; + } + /** * Return the <code>MethodProxy</code> used when intercepting the method * matching the given signature. diff --git a/src/test/net/sf/cglib/proxy/TestEnhancer.java b/src/test/net/sf/cglib/proxy/TestEnhancer.java index befbc1c..5de6a9f 100644 --- a/src/test/net/sf/cglib/proxy/TestEnhancer.java +++ b/src/test/net/sf/cglib/proxy/TestEnhancer.java @@ -19,13 +19,14 @@ import java.io.*; import java.lang.reflect.*; import junit.framework.*; import net.sf.cglib.CodeGenTestCase; +import net.sf.cglib.core.DefaultNamingPolicy; import net.sf.cglib.core.ReflectUtils; import net.sf.cglib.reflect.FastClass; /** *@author Juozas Baliuka <a href="mailto:bali...@mwm.lt"> * bali...@mwm.lt</a> - *@version $Id: TestEnhancer.java,v 1.55 2005/10/11 07:13:32 baliuka Exp $ + *@version $Id: TestEnhancer.java,v 1.56 2009/01/11 19:47:50 herbyderby Exp $ */ public class TestEnhancer extends CodeGenTestCase { private static final MethodInterceptor TEST_INTERCEPTOR = new TestInterceptor(); @@ -443,6 +444,38 @@ public class TestEnhancer extends CodeGenTestCase { assertTrue("boop".equals(d.herby())); } + static class NamingPolicyDummy {} + + public void testNamingPolicy() throws Throwable { + Enhancer e = new Enhancer(); + e.setSuperclass(NamingPolicyDummy.class); + e.setUseCache(false); + e.setUseFactory(false); + e.setNamingPolicy(new DefaultNamingPolicy() { + public String getTag() { + return "ByHerby"; + } + public String toString() { + return getTag(); + } + }); + e.setCallbackType(MethodInterceptor.class); + Class proxied = e.createClass(); + final boolean[] ran = new boolean[1]; + Enhancer.registerStaticCallbacks(proxied, new Callback[]{ + new MethodInterceptor() { + public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable { + ran[0] = true; + assertTrue(proxy.getSuperFastClass().getClass().getName().indexOf("$FastClassByHerby$") >= 0); + return proxy.invokeSuper(obj, args); + } + } + }); + NamingPolicyDummy dummy = (NamingPolicyDummy) proxied.newInstance(); + dummy.toString(); + assertTrue(ran[0]); + } + public static Object enhance(Class cls, Class interfaces[], Callback callback, ClassLoader loader) { Enhancer e = new Enhancer(); e.setSuperclass(cls);
signature.asc
Description: Digital signature
__ This is the maintainer address of Debian's Java team <http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-java-maintainers>. Please use debian-j...@lists.debian.org for discussions and questions.