atos1990 / orika

Automatically exported from code.google.com/p/orika
0 stars 0 forks source link

CDI Bean Inheriting from CustomConverter throws Exception on construct #81

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Inherit a CDI Bean from CustomConverter
2. Inject the bean somewhere

What is the expected output? What do you see instead?

Bean inject should succeed. Instead it throws an IllegalArgumentException.

Caused by: java.lang.IllegalStateException: When you subclass the ConverterBase 
S and D type-parameters are required.
    at ma.glasnost.orika.CustomConverter.<init>(CustomConverter.java:49) [orika-core-1.4.0.jar:]
    at uk.co.kraya.invision.goals.common.converters.DomainToLongConverter.<init>(DomainToLongConverter.java:14) [goals-0.0.1-SNAPSHOT.jar:]
    at uk.co.kraya.invision.goals.common.converters.DomainToLongConverter$Proxy$_$$_WeldClientProxy.<init>(DomainToLongConverter$Proxy$_$$_WeldClientProxy.java) [goals-0.0.1-SNAPSHOT.jar:]
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) [rt.jar:1.7.0_11]
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) [rt.jar:1.7.0_11]
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) [rt.jar:1.7.0_11]
    at java.lang.reflect.Constructor.newInstance(Constructor.java:525) [rt.jar:1.7.0_11]
    at java.lang.Class.newInstance0(Class.java:372) [rt.jar:1.7.0_11]
    at java.lang.Class.newInstance(Class.java:325) [rt.jar:1.7.0_11]
    at org.jboss.weld.util.reflection.SecureReflections$16.work(SecureReflections.java:343) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]
    at org.jboss.weld.util.reflection.SecureReflectionAccess.run(SecureReflectionAccess.java:52) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]
    at org.jboss.weld.util.reflection.SecureReflectionAccess.runAsInstantiation(SecureReflectionAccess.java:173) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]
    ... 105 more

It looks like the magic that CDI does breaks the genericSuperclass check

What version of the product are you using? On what operating system?

1.4.0 on Linux. CDI with Weld on JBoss

Please provide any additional information below.

Original issue reported on code.google.com by shriram....@gmail.com on 31 Jan 2013 at 2:53

GoogleCodeExporter commented 9 years ago
Did you provide S and D arguments when you're subclassing ConverterBase ?

Original comment by elaat...@gmail.com on 31 Jan 2013 at 3:06

GoogleCodeExporter commented 9 years ago
I assume so since the converter class seems to work fine when I do unit testing 
with it. i.e. out of container testing.

It fails with the above error when I inject the class using CDI / Weld ONLY.

Original comment by shriram....@gmail.com on 31 Jan 2013 at 5:39

GoogleCodeExporter commented 9 years ago
Can you please try to use a factory method, to instantiate your converter. 

Original comment by elaat...@gmail.com on 31 Jan 2013 at 5:49

GoogleCodeExporter commented 9 years ago
After some investigation, I have stumbled across something interesting. I have 
this issue when I define the scope of the converter bean to be 
@ApplicationScoped 

If it is dependent scope, which is the default, it works fine. 

I think this has something to do with Proxying & Passivation. I do not know the 
CDI spec well enough but from what I understand, a proxy is used for long-life 
beans (like ones which are application scoped). These are then passivated when 
not used and brought back to life when necessary. 

I was trying to use ApplicationScoped since there is no need to have multiple 
copies of the bean hanging about. 

This can be worked around. It may be enough to document this limitation since 
it impacts a very specific case.

Original comment by shriram....@gmail.com on 4 Feb 2013 at 12:36

GoogleCodeExporter commented 9 years ago
Many thanks for the explanation as you suggest may be a wiki page with known 
issues / limitations should be helpful for people considering using Orika.

Original comment by elaat...@gmail.com on 4 Feb 2013 at 12:47

GoogleCodeExporter commented 9 years ago

Original comment by elaat...@gmail.com on 4 Feb 2013 at 12:47