yuskam / catch-exception

Automatically exported from code.google.com/p/catch-exception
0 stars 0 forks source link

compatibility with spring proxy #10

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
when using catch-exception and spring proxy on same class, both framework tries 
to generate same class name and the latter one fails. maybe some random string 
should be added to generated class name.

it fails even when each technique is used in completely different test (because 
classloader keeps the generated class)

detailed description can be found here: 
http://blog.piotrturski.net/2013/06/codegenerationexception-and-proxies.html

Original issue reported on code.google.com by Piotr.Tu...@gmail.com on 16 Sep 2013 at 10:55

GoogleCodeExporter commented 8 years ago
When injecting beans via spring and in same test, you call CatchException, 
there is no problem with classNames. The problems rises when running tests with 
and without spring.

Original comment by federico...@gmail.com on 1 Nov 2013 at 5:34

GoogleCodeExporter commented 8 years ago
AFAIK catch-exception is using mockito, right? there is no such problem when 
using plain mockito. do you know what exactly is causing the problem? more 
details would be helpful. maybe i could create a patch, rise a ticket for 
spring team or at least find some workaround

Original comment by Piotr.Tu...@gmail.com on 1 Nov 2013 at 9:04

GoogleCodeExporter commented 8 years ago
As described in: 
http://blog.piotrturski.net/2013/06/codegenerationexception-and-proxies.html
The problem is mixing spring + catch-exception. 
If i run a spring+junit+catch-exception test, there is no problem at all. But 
when i run junit-catch-exception test (catch-exception proxy around class A) 
and then spring+junit+catch-exception test (spring proxy around class A) then 
the problem rises:

java.lang.LinkageError: loader (instance of  sun/misc/Launcher$AppClassLoader): 
attempted  duplicate class definition for name: "A$$FastClassByCGLIB$$441a78f3"

Will try to have more details to provide.

Cheers

Original comment by federico...@gmail.com on 1 Nov 2013 at 9:12

GoogleCodeExporter commented 8 years ago
I have dived into darkness to found what the problem was. Here we go:

CatchException is using Cglib through Mockito. 

When using standalone Mockito, it uses its own NamingPolicy 
(org.mockito.internal.creation.cglib.MockitoNamingPolicy) which tag its proxy 
with "ByMockitoWithCGLIB". So every proxy differs from others proxy, like ones 
created by SpringAOP (in my case)

CatchException hasn't this "feature" and used default naming policy, so when i 
call my catch-exception+junit test it creates a proxy named 
A$$FastClassByCGLIB$$8a285887.  Just before, when catch-exception+junit+spring 
test run, com.googlecode.catchexception.internal.ExceptionProcessingInterceptor 
also creates a proxy named A$$FastClassByCGLIB$$8a285887 (cause it used cglib 
DefaultNamePolicy). There is where the name clashing happens.

ExceptionProcessingInterceptor {
 #intercept() {
  ...
  Object retval = proxy.invoke(target, args);
  ...
 }
}

MethodProxy calls AbstractClassGenerator fromEnhancer = 
AbstractClassGenerator.getCurrent(); who return an Enhancer with defaultPolicy

Hope it helps

Original comment by federico...@gmail.com on 2 Nov 2013 at 12:36

GoogleCodeExporter commented 8 years ago
Got it fixed. I'm going to upload a patch for this one.

Original comment by federico...@gmail.com on 2 Nov 2013 at 1:22

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
Attached patch. All test run correctly (Including 
com.googlecode.catchexception.internal.ExceptionProcessingInterceptorTest)
Any problem, just let me know.

Original comment by federico...@gmail.com on 4 Nov 2013 at 11:48

Attachments:

GoogleCodeExporter commented 8 years ago
Federico, thank you for your patch!

The patch is applied. The next release of catch-exception is coming soon.

Piotr, thank you for providing an integration test.

Original comment by rwoo@gmx.de on 4 Nov 2013 at 7:30

GoogleCodeExporter commented 8 years ago
i can confirm that this patch solves all my issues. now, waiting for the 
release :)

Original comment by Piotr.Tu...@gmail.com on 5 Nov 2013 at 12:05

GoogleCodeExporter commented 8 years ago

Original comment by rwoo@gmx.de on 5 Nov 2013 at 6:46

GoogleCodeExporter commented 8 years ago

Original comment by rwoo@gmx.de on 6 Nov 2013 at 1:18