Proxy on package scope methods
Henri Tremblay <[email protected]> Tue, 18 Oct 2011 02:06:24 +0200
| Newsgroups | gmane.comp.java.cglib.devel |
|---|---|
| Message-ID | <CADZL2=t0qQjPYXhmH=aaokAny-ECY76r625onHJcP8vzCj+JgQ@mail.gmail.com> |
Hi,
I'm looking for some help. I'm having issues with bridge methods. I'm doing,
a you probably know, my EasyMock mocks using cglib. Cglib is normally
proxying both the bridge method and the real method. So, I normally keep the
bridge method normal behavior and the real method is mocked.
This works fine except in one case. When the base class is packaged scope.
In that case, the JDK (maven compilation) is creating a bridge method.
Eclipse does not. This should not be an issue but cglib doesn't proxy the
package scope method.. So the bridge keeps its usual behavior which call the
real method instead of the proxy that should mock it. And so everything
fails.
Three things are important to note:
- Only the JDK (1.6.0_27) is creating the bridge
- The bridge is created because the base class is package scope
- The bridges method is defined on the base class
Here is a test case
public class CglibBridgeTest {
static abstract class AbstractFoo {
public String getSomeStrings() {
// new Exception().printStackTrace(); // shows the direct
delegation to the bridge
return null;
}
}
public static class ConcreteFoo extends AbstractFoo {
}
private int counter;
@Test
public void test() {
final ConcreteFoo foo = (ConcreteFoo)
Enhancer.create(ConcreteFoo.class, new MethodInterceptor() {
public Object intercept(final Object obj, final Method method,
final Object[] args,
final MethodProxy proxy) throws Throwable {
counter++;
// System.out.println("Method: " + method); // shows that
only the bridge is proxied
return proxy.invokeSuper(obj, args);
}
});
counter = 0;
foo.getSomeStrings();
assertEquals(2, counter);
}
}
I would expect to have two calls to the proxy but
- Only the bridge is proxied
- There's a ConcreteFoo.getSomeStrings bridge created
Can you help me to get the wanted behavior?
Thanks
-
Henri
------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure contains a
definitive record of customers, application performance, security
threats, fraudulent activity and more. Splunk takes this data and makes
sense of it. Business sense. IT sense. Common sense.
http://p.sf.net/sfu/splunk-d2d-oct
_______________________________________________
cglib-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/cglib-devel