aucd29 / cloning

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

IllegalArgumentException on clone #16

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
Have not managed to reproduce what causes this. Is was detected in our logs. 
When cloning example instances of the failing object, it works.

What is the expected output?
A cloned object.

What do you see instead?
java.lang.IllegalArgumentException: Can not set java.lang.String field 
<package>.<Class>.stringField to <package>.<Class> at 
sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeField
AccessorImpl.java:146) ~[na:1.6.0_22] at 
sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeField
AccessorImpl.java:150) ~[na:1.6.0_22] at 
sun.reflect.UnsafeFieldAccessorImpl.ensureObj(UnsafeFieldAccessorImpl.java:37) 
~[na:1.6.0_22] at 
sun.reflect.UnsafeObjectFieldAccessorImpl.set(UnsafeObjectFieldAccessorImpl.java
:57) ~[na:1.6.0_22] at java.lang.reflect.Field.set(Field.java:657) 
~[na:1.6.0_22] at 
com.rits.cloning.Cloner.cloneInternal(com.rits.cloning.Cloner:405) 
~[cloning-1.7.4.jar:na] at 
com.rits.cloning.FastClonerArrayList.clone(com.rits.cloning.FastClonerArrayList:
22) ~[cloning-1.7.4.jar:na]

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

Please provide any additional information below.
Happens in webapp on weblogic 10.3.4. Cloning object in a spring (3.0.5) 
aspect, to use for caching.
It seems the cloner tries to assign a string field from source object to the 
destination object itself (not the string field in the destination object)

Original issue reported on code.google.com by rikardsw...@gmail.com on 18 Dec 2012 at 12:03

GoogleCodeExporter commented 9 years ago
did you tried the latest version?

https://oss.sonatype.org/content/repositories/releases/uk/com/robust-it/cloning/

Original comment by kostas.k...@googlemail.com on 7 Mar 2013 at 10:27

GoogleCodeExporter commented 9 years ago
No, did not use last version, tought that 1.7.4 was the last version, will try 
it and come back if it still happens.

Original comment by rikardsw...@gmail.com on 12 Mar 2013 at 12:14

GoogleCodeExporter commented 9 years ago
The same is with 1.9.0 (used within tomcat 7)
2013-04-03 01:57:43 [jw.egrasp.dom-startStop-1] ERROR 
org.springframework.web.context.ContextLoader - Context initialization failed
java.lang.IllegalArgumentException: Can not set boolean field 
com.evalica.acc.domain.field.EmployerReferenceField.showEmployerName to 
com.evali
ca.acc.domain.field.EmployerReferenceField
        at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:146)
        at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:150)
        at sun.reflect.UnsafeFieldAccessorImpl.ensureObj(UnsafeFieldAccessorImpl.java:37)
        at sun.reflect.UnsafeBooleanFieldAccessorImpl.set(UnsafeBooleanFieldAccessorImpl.java:57)
        at java.lang.reflect.Field.set(Field.java:657)
        at com.rits.cloning.Cloner.cloneInternal(Cloner.java:515)
        at com.rits.cloning.Cloner.deepClone(Cloner.java:323)
        at com.evalica.acc.util.Utils.cloneDeeply(Utils.java:1724)
        at com.evalica.acc.domain.cache.EhcacheCopyStrategyBase.copyElement(EhcacheCopyStrategyBase.java:29)

Original comment by alex...@aspentechlabs.com on 2 Apr 2013 at 11:06

GoogleCodeExporter commented 9 years ago
So if you create  a testcase testing with a couple of instances of 
EmployerReferenceField, does it reproduce?

If not, do you use proxies (i.e. cgi or asm?). If you debug, does 
EmployerReferenceField gain any fields due to proxies?

Original comment by kostas.k...@googlemail.com on 3 Apr 2013 at 8:20

GoogleCodeExporter commented 9 years ago
I'm also usign Weblogic 10.3.4, Spring 3.0 and Hibernate Annotations, and I 
obtain the same error. I think that the error is produced by Hibernate Proxies.
I tried to load the entire real object from the database but it still throws 
the exception. 

This problem only ocurrs on Weblogic. I deployed the application on Tomcat 6 
and the clonation works perfectly.

In addition, I have redefined the cloneInternal method in order to clone 
Hibernate managed objects by deleting(assign to null) the @id property and it 
works.

How can I solve this problem?

Thanks!

Original comment by r.vegas1...@gmail.com on 11 Apr 2013 at 4:57

GoogleCodeExporter commented 9 years ago
what happens if you do cloner.nullInsteadOfClone for these classes (and all 
other hibernate classes that you might be using)?

org.hibernate.engine.SessionImplementor
org.hibernate.impl.SessionImpl
org.hibernate.impl.StatelessSessionImpl
org.hibernate.transaction.JDBCTransaction

Original comment by kostas.k...@googlemail.com on 13 Apr 2013 at 5:43

GoogleCodeExporter commented 9 years ago
I set the cloningEnabled flag to true and did cloner.nullInsteadOfClone for 
SessionImplementor, SessionImpl, StatelessSessionImpl and JDBCTransaction.

Now it works fine! 

Thank you very much for solving my problem :)

Original comment by r.vegas1...@gmail.com on 15 Apr 2013 at 7:14

GoogleCodeExporter commented 9 years ago
Cheers, closing this issue

Original comment by kostas.k...@googlemail.com on 16 Apr 2013 at 7:51

GoogleCodeExporter commented 9 years ago
I still having this issue. The issue happens within one of 2 applications 
loaded on tomcat 7.
If only one application loaded - all is fine. If two same applications loaded 
one is OK, the second has java.lang.IllegalArgumentException: Can not set 
boolean field 
com.evalica.acc.domain.field.EmployerReferenceField.showEmployerName to 
com.evalica.acc.domain.field.EmployerReferenceField
Strange thing is that cloner tries to set EmployerReferenceField (that is not 
boolean) to boolean EmployerReferenceField.showEmployerName.
This issue is not appears on cloner versions 1.8.1 and lower. And appears on 
all 1.8.2+.

Cloner library is within tomcat/lib folder and not separate for each 
WEB-INF/lib folder. Maybe this is the reason?

Original comment by alex...@aspentechlabs.com on 6 Nov 2013 at 1:25

GoogleCodeExporter commented 9 years ago
Suppose it may be because of static singleton and if cloner library is shared 
between tomcat apps - we may fail and intersection of cloning objects.
This singleton is not used in version 1.8.1 and lower.
Singleton:
public class ObjenesisInstantiationStrategy implements IInstantiationStrategy
{
    private final Objenesis objenesis   = new ObjenesisStd();

    @SuppressWarnings("unchecked")
    public <T> T newInstance(Class<T> c)
    {
        return (T) objenesis.newInstance(c);
    }

    private static ObjenesisInstantiationStrategy   instance    = new ObjenesisInstantiationStrategy();

    public static ObjenesisInstantiationStrategy getInstance()
    {
        return instance;
    }
}

Original comment by alex...@aspentechlabs.com on 6 Nov 2013 at 1:35

GoogleCodeExporter commented 9 years ago
The Cloner has a constructor:

    public Cloner(final IInstantiationStrategy instantiationStrategy)

Instead of calling the default constructor, just call this one as :

new Cloner(new ObjenesisInstantiationStrategy())

1 instance of ObjenesisInstantiationStrategy per web app is required.

Does this work?

Original comment by kostas.k...@googlemail.com on 23 Nov 2013 at 4:52