Giter VIP home page Giter VIP logo

cloning's People

Contributors

kostaskougios avatar

Watchers

 avatar

cloning's Issues

Can you please tell me how to soft-clone (i.e. set references) or NULL for a Set in my class

I have a Entity class A.java
it has some fields and some Set<otherEntity> of OtherEntity.java

Now I want to clone A.java but don't want the Set to be cloned, i.e. it should 
only refer the same set as that of source Entity A.java, similar to what 
happens when I used dontClone() method for some class and that Class (if 
encountered) in the source Entity then it is referenced with the same object 
instead of cloning.
Scenario:
Class A {
field f1;
field f2;
Set<B> bSet;
}
Class B {
field b1;
field b2;
}
Now I want to clone A
Expected:
A new Object (say C) with all the fields cloned from A.
but bSet of C should share the reference with bSet of A.

Looking forward for a quick response.
Thanks in advance.

Original issue reported on code.google.com by [email protected] on 17 Apr 2013 at 6:00

ConcurrentModificationException

Caused by: java.util.ConcurrentModificationException
    at java.util.LinkedList$ListItr.checkForComodification(LinkedList.java:953)
    at java.util.LinkedList$ListItr.next(LinkedList.java:886)
    at com.rits.cloning.FastClonerLinkedList.clone(FastClonerLinkedList.java:18)
    at com.rits.cloning.Cloner.fastClone(Cloner.java:108)
    at com.rits.cloning.Cloner.cloneInternal(Cloner.java:460)
    at com.rits.cloning.Cloner.cloneInternal(Cloner.java:514)
    at com.rits.cloning.Cloner.cloneInternal(Cloner.java:514)
    at com.rits.cloning.Cloner.cloneInternal(Cloner.java:514)
    at com.rits.cloning.Cloner.cloneInternal(Cloner.java:514)
    at com.rits.cloning.Cloner.cloneInternal(Cloner.java:514)
    at com.rits.cloning.Cloner.cloneInternal(Cloner.java:485)
    at com.rits.cloning.Cloner.cloneInternal(Cloner.java:514)
    at com.rits.cloning.Cloner.cloneInternal(Cloner.java:514)
    at com.rits.cloning.Cloner.cloneInternal(Cloner.java:514)
    at com.rits.cloning.Cloner.cloneInternal(Cloner.java:514)
    at com.rits.cloning.Cloner.cloneInternal(Cloner.java:514)
    at com.rits.cloning.Cloner.cloneInternal(Cloner.java:514)
    at com.rits.cloning.Cloner.cloneInternal(Cloner.java:485)
    at com.rits.cloning.Cloner.cloneInternal(Cloner.java:514)
    at com.rits.cloning.Cloner.cloneInternal(Cloner.java:514)
    at com.rits.cloning.Cloner.cloneInternal(Cloner.java:514)
    at com.rits.cloning.Cloner.cloneInternal(Cloner.java:514)
    at com.rits.cloning.Cloner.cloneInternal(Cloner.java:514)
    at com.rits.cloning.Cloner.cloneInternal(Cloner.java:514)
    at com.rits.cloning.Cloner.cloneInternal(Cloner.java:485)
    at com.rits.cloning.Cloner.cloneInternal(Cloner.java:514)
    at com.rits.cloning.FastClonerConcurrentHashMap.clone(FastClonerConcurrentHashMap.java:21)
    at com.rits.cloning.Cloner.fastClone(Cloner.java:108)
    at com.rits.cloning.Cloner.cloneInternal(Cloner.java:460)
    at com.rits.cloning.Cloner.cloneInternal(Cloner.java:514)
    at com.rits.cloning.Cloner.cloneInternal(Cloner.java:514)
    at com.rits.cloning.Cloner.cloneInternal(Cloner.java:514)
    at com.rits.cloning.Cloner.cloneInternal(Cloner.java:514)
    at com.rits.cloning.Cloner.cloneInternal(Cloner.java:514)
    at com.rits.cloning.Cloner.deepClone(Cloner.java:323)

Original issue reported on code.google.com by [email protected] on 15 May 2014 at 3:50

Caused by: java.lang.IllegalArgumentException: Can not set

What steps will reproduce the problem?
When object is deepcloned.

What is the expected output?
A successful cloned object.

What do you see instead?
Caused by: java.lang.IllegalArgumentException: Can not set <package.AAA> field 
A.a to A
        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.UnsafeQualifiedObjectFieldAccessorImpl.set(UnsafeQualifiedObjectFieldAccessorImpl.java:59)
        at java.lang.reflect.Field.set(Field.java:657)
        at com.rits.cloning.Cloner.cloneInternal(Cloner.java:515)
        at com.rits.cloning.Cloner.cloneInternal(Cloner.java:514)
        at com.rits.cloning.Cloner.cloneInternal(Cloner.java:514)
        at com.rits.cloning.Cloner.cloneInternal(Cloner.java:514)
        at com.rits.cloning.Cloner.cloneInternal(Cloner.java:514)
        at com.rits.cloning.FastClonerArrayList.clone(FastClonerArrayList.java:20)
        at com.rits.cloning.Cloner.fastClone(Cloner.java:108)
        at com.rits.cloning.Cloner.cloneInternal(Cloner.java:460)
        at com.rits.cloning.Cloner.cloneInternal(Cloner.java:514)
        at com.rits.cloning.Cloner.deepClone(Cloner.java:323)


What version of the product are you using? On what operating system?
1.9.0
Linux RHEL 6

Please provide any additional information below.
I'm using Jetty has embebbed aplication server.

Original issue reported on code.google.com by [email protected] on 16 Sep 2013 at 10:33

No way to replace FastCloner

registerFastCloner() throws an exception when an attempt it made to replace one 
of the existing, default, fast cloners.

It should:
* silently accept or
* there should be a method to unregister or
* a method to add w/replace if needed (leaving the original add throwing an 
exception)

Original issue reported on code.google.com by [email protected] on 22 May 2014 at 5:35

The isImmutable cache isn't always used

I noticed in Cloner.isImmutable only caches @Immutable if it finds one, not if 
it doesn't.

Should be enough with:
if (b != null) return b; // at the top
immutables.put(clz, Boolean.FALSE); //just before it returns false

Original issue reported on code.google.com by [email protected] on 19 May 2014 at 8:23

Android Support

cloning, any version
Android, any version

Cloning requires objenesis which requires sun.reflect.ReflectionFactory in 
order to instantiate without a constructor.

While objenesis plans to support Android, the ticket has been sitting 
'accepted' since 2010 and no release of objenesis has been made since then!  
The direct workaround is mentioned here:

http://stackoverflow.com/questions/3121515/is-it-possible-to-bypass-constructors
-when-instantiating-objects-in-android

Looks simple enough, no?  Detect a running Android VM and change the 
newInstance() implementation.  I may fork and give it a try.

Original issue reported on code.google.com by [email protected] on 4 Jul 2012 at 7:53

Fast cloners should use interface not implementation

In the fast cloners the object to be cloned is passed in and type cast to an 
implementation, such as HashMap:

        final HashMap<Object, Object> m = (HashMap) t;

It should be type cast to the interface for those collections such as:

        final Map<Object, Object> m = (Map) t;

This then allows the use of the existing fast cloners for other collection 
implementations such as Hibernate's PersistentMap or PersistentSet.

Original issue reported on code.google.com by [email protected] on 22 May 2014 at 6:28

Documentation says that I can use one instance of Cloner throughout the application

What steps will reproduce the problem?
1. Create an instance of Cloner
2. Invoke the method 'nullInsteadOfClone' with a valid argument on that instance
3. 'deepClone' it
4. Invoke the method 'registerImmutable' with the same argument on step 2 on 
the same instance created
5. 'deepClone' it again. The line unit-test validation line 
'assertTrue(clonedPerson.profession != null);' in the unit-test below fails as 
profession is null.

What is the expected output? What do you see instead?
Expected: The cloned object with the same instance of its mutable internal 
object which was explicitly chosen not to be cloned.
Actual result: The internal object above is null.

What version of the product are you using? On what operating system?
Product version: 1.7.9
OS: Windows XP Professional SP3

Please provide any additional information below.
Please note that this issue relates to (what I believe to be) a bug in 
documentation which states "You can create a single instance of cloner and use 
it throughout your application[...]".
Find below the Utility class I created to encapsulate 'Cloner' and below it the 
relevant part of the unit-tests I was working on:
============= UTIL CLASS ===========================
import com.rits.cloning.Cloner;

/**
 * 
 * @author fabio.serragnoli
 */
public final class CloneUtils {
    private static final Cloner CLONER = new Cloner(); 

    public static <T> T shallowClone(final T pToBeClonedObject) {
    final T clonedObject = CLONER.shallowClone(pToBeClonedObject);

    return clonedObject;
    }

    public static <T> T deepCloneNullInsteadOfClone(final T pToBeClonedObject, final Class<?>... pNullInsteadOfClone) {
    CLONER.nullInsteadOfClone(pNullInsteadOfClone);
    final T clonedObject = CLONER.deepClone(pToBeClonedObject);

    return clonedObject;
    }

    public static <T> T deepCloneRegisterImmutable(final T pToBeClonedObject, final Class<?>... pImmutable) {
    CLONER.registerImmutable(pImmutable);
    final T clonedObject = CLONER.deepClone(pToBeClonedObject);

    return clonedObject;
    }
}

============= UNIT TEST CLASS ===========================
import java.util.HashSet;
import java.util.Set;

import org.junit.Test;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertThat;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.nullValue;;

/**
 * 
 * @author fabio.serragnoli
 *
 */
public class CloneUtilsTest {

    @Test
    public void deepCloneWithInternalMutableObjectChosenToBeNull() {
    final Person person = new Person();
    final City nyc = new City("NYC");
    final Profession profession = new Profession("Musician");
    person.visitedCities.add(nyc);
    person.profession = profession;

    final Person clonedPerson = CloneUtils.deepCloneNullInsteadOfClone(person, Profession.class);   

    assertThat(clonedPerson.profession, is(nullValue()));   
    }

    @Test
    public void deepCloneWithInternaMutableObjectChosenNotToBeCloned() {
    final Person person = new Person();
    final City nyc = new City("NYC");
    final Profession profission = new Profession("Musician");
    person.visitedCities.add(nyc);
    person.profession = profission;

    final Person clonedPerson = CloneUtils.deepCloneRegisterImmutable(person, Profession.class);    

    assertTrue(clonedPerson.profession != null);
    }

   private static class Person {
    private String name = "Jerry Lee Lewis";
    private Set<City> visitedCities = new HashSet<City>();
    private Profession profession = new Profession("Singer");
    }

    private static class Profession {
    private String name;

    Profession(final String pName) {
        this.name = pName;
    }
    }

    private static class City {
    private String name;

    City(final String pName) {
        name = pName;
    }   
    }
}

Original issue reported on code.google.com by [email protected] on 29 Feb 2012 at 6:51

IDumpCloned improvments

Looks like both the two deepClone() methods and the cloneInternal both call 
startCloning()... makes it difficult to determine when an object is actually 
being "started".

To mirror the previous "functionality" you'd need an additional callback/method 
on the interface as previously "start>" was output followed by "clone>" 
followed by "cloned field>"

I think there is benefit in adding that additional callback on the interface.

It would also be useful if objects were passed to the callbacks instead of the 
Class of the object:
* startCloning() is passed o
* new callback (ie the "clone>" replacement) is passed o
* the field callback, cloning() is passed both o, along with fieldObject

This allows dumping details of the actual object vs just the class name.

Original issue reported on code.google.com by [email protected] on 26 Jun 2014 at 11:48

Enum Cloning throws IllegalArgumentException

Steps to rep
1. Create a Enum with a body including a static final field.
2. But it into a Map.
3. Clone the Map.

The cloner throws an java.lang.IllegalArgumentException: Can not set final 
java.lang.String field com.customweb.payment.bean.context.BuildMode.name to 
com.customweb.payment.bean.context.BuildMode$6 (full stack trace is attached).


Cloner Version:
1.9.0


The exception should be fixable by using Class.getDeclaringClass() instead of 
Class.getClass() for checking if a given object is an Enum or not in 
com.rits.cloning.Cloner on line 443 (see also 
http://stackoverflow.com/questions/5758660/java-enum-getdeclaringclass-vs-getcla
ss?rq=1). 

Original issue reported on code.google.com by [email protected] on 20 Jul 2013 at 9:40

Attachments:

Ignore fields when clonning objects

Hi, I would like to ignore some fields of the objects beeing cloned. This 
feature is simlar to the nullTransient but I cannot make the fields transient. 

A solution is annotating the fileds with something like @CloningIgnore. 

I am trying to extend the Cloner class to support that feature but some of the 
methods are private. I think extending or updating 'private List<Field> 
allFields(final Class<?> c)' will do the trick. 

Thanks
Fernando


Original issue reported on code.google.com by [email protected] on 13 Aug 2012 at 11:43

Not working with Android 4.3

This cloning library doesn't work on Android 4.3.

Caused by: org.objenesis.ObjenesisException: java.lang.NoSuchMethodException: 
newInstance [class java.lang.Class, int]

See also: https://groups.google.com/forum/#!topic/objenesis-dev/jdqWCwy5E78

According to this thread, Objenesis lib has been updated to support Android 4.3.
Your library still uses an old version of Objenesis, can you upgrade?

Original issue reported on code.google.com by [email protected] on 19 Sep 2014 at 2:14

Wrong class taken when cloning anonymous classes

What steps will reproduce the problem?

1. try this code:

import com.rits.cloning.Cloner;
import java.util.Map.Entry;
import java.util.logging.Logger;
import org.junit.Test;

/**
 *
 * @author Marek Bukowy
 */
public class CloneInnerAnonTest {

    private Logger logger = Logger.getAnonymousLogger();

    @Test
    public void helloTest() {

        Cloner cl = new Cloner();
        cl.setDumpClonedClasses(true);

        Entry<Object, String> a = new Entry<Object, String>() {
            public Object getKey() {
                return null;
            }

            public String getValue() {
                return "";
            }

            public String setValue(String value) {
                return "";
            }          
        };

        cl.deepClone(a);     
    }
}

This test case can be extended to have a mock interceptor as a private field in 
the CloneInnerAnonTest class, and an assert on number of invocations (should be 
0 if cloner does not touch those private fields).

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

I think it is wrong that the cloner goes into the parent class. It should 
recognize that it is an implementation of Map.Entry and stop there. Even if 
formally correct as a Java concept, I believe there should be a switch that 
controls this behaviour.

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

cloning 1.8.1
objenesis 1.2

java version "1.6.0_22"
OpenJDK Runtime Environment (IcedTea6 1.10.6) (6b22-1.10.6-0ubuntu1)
OpenJDK 64-Bit Server VM (build 20.0-b11, mixed mode)

Please provide any additional information below.

When run inside a tomcat app, with the "parent" class having a few key system 
elements as fields - for example as innocent as a Mockito mock, it goes very 
quickly into cloning almost every conceivable object in the application, 
usually ending up with a JVM crash like this:

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x00007f97c18874c3, pid=7677, tid=140289463260928
#
# JRE version: 6.0_26-b03
# Java VM: Java HotSpot(TM) 64-Bit Server VM (20.1-b02 mixed mode linux-amd64 
compressed oops)
# Problematic frame:
# C  [libzip.so+0xb4c3]  ZIP_GetEntry+0x33
#
# If you would like to submit a bug report, please visit:
#   http://java.sun.com/webapps/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#


Original issue reported on code.google.com by [email protected] on 22 Aug 2012 at 9:59

NullPointerReference by call shallowClone()

What steps will reproduce the problem?
1. Create map with array as value.
2. Call shallowClone() method.
3.

What is the expected output? What do you see instead?
Expected - copy, see -  NullPointerException

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

Please provide any additional information below.
Ver 179 in Cloner line 422 check for null is needed.
clones.put(o, newInstance); -> if (clones!=null)clones.put(o, newInstance);

Original issue reported on code.google.com by [email protected] on 8 May 2012 at 7:58

Intensive use of a stack

Cloning large object graphs might cause StackOverflowException as it did in my 
case. To overcome this problem I use jvm directive -Xss1028k. 

It should be possible to optimize algorithm by replacing recursion with 
iterative approach.

Original issue reported on code.google.com by [email protected] on 8 Nov 2012 at 11:04

assign feature

Adding this would allow transferring from one object to another:

    public <T> void assign(T target, T o) {
        if (o == null) {
            return;
        }
        if (dumpClonedClasses) {
            System.out.println("start assign>" + o.getClass());
        }
        final Map<Object, Object> clones = new IdentityHashMap<Object, Object>(16);
        try {
            cloneInternal(o, target, clones);
        } catch (final IllegalAccessException e) {
            throw new CloningException("error during cloning of " + o, e);
        }
    }


and cloneInternal modified little bit, I just dump it here:

public <T> T cloneInternal(final T o, final T startWith, final Map<Object, 
Object> clones) throws IllegalAccessException {
        if (o == null) {
            return null;
        }
        if (o == this) {
            return null;
        }
        if (ignoredInstances.containsKey(o)) {
            return o;
        }
        final Class<T> clz;
        if (startWith != null) {
            clz = (Class<T>) startWith.getClass();
        } else {
            clz = (Class<T>) o.getClass();
        }
        if (clz.isEnum()) {
            return o;
        }
        // skip cloning ignored classes
        if (nullInstead.contains(clz)) {
            return null;
        }
        if (ignored.contains(clz)) {
            return o;
        }
        for (final Class<?> iClz : ignoredInstanceOf) {
            if (iClz.isAssignableFrom(clz)) {
                return o;
            }
        }
        if (isImmutable(clz)) {
            return o;
        }
        if (o instanceof IFreezable) {
            final IFreezable f = (IFreezable) o;
            if (f.isFrozen()) {
                return o;
            }
        }
        final Object clonedPreviously = clones != null ? clones.get(o) : null;
        if (clonedPreviously != null) {
            return (T) clonedPreviously;
        }

        final Object fastClone = fastClone(o, clones);
        if (fastClone != null) {
            if (clones != null) {
                clones.put(o, fastClone);
            }
            return (T) fastClone;
        }

        if (dumpClonedClasses) {
            System.out.println("clone>" + clz);
        }
        if (clz.isArray()) {
            final int length = Array.getLength(o);
            final T newInstance = (T) Array.newInstance(clz.getComponentType(), length);
            if (clones != null) {
                clones.put(o, newInstance);
            }
            for (int i = 0; i < length; i++) {
                final Object v = Array.get(o, i);
                final Object clone = clones != null ? cloneInternal(v, null, clones) : v;
                Array.set(newInstance, i, clone);
            }
            return newInstance;
        }

        final T newInstance;
        if (startWith != null) {
            newInstance = startWith;
        } else {
            newInstance = newInstance(clz);
        }
        if (clones != null) {
            clones.put(o, newInstance);
        }
        final List<Field> fields = allFields(clz);
        for (final Field field : fields) {
            final int modifiers = field.getModifiers();
            if (!Modifier.isStatic(modifiers)) {
                if (nullTransient && Modifier.isTransient(modifiers)) {
                    // request by Jonathan : transient fields can be null-ed
                    final Class<?> type = field.getType();
                    if (!type.isPrimitive()) {
                        field.set(newInstance, null);
                    }
                } else {
                    final Object fieldObject = field.get(o);
                    final boolean shouldClone = (cloneSynthetics || !cloneSynthetics && !field.isSynthetic()) && (cloneAnonymousParent || !cloneAnonymousParent && !isAnonymousParent(field));
                    final Object fieldObjectClone = clones != null ? shouldClone ? cloneInternal(fieldObject, null, clones) : fieldObject : fieldObject;
                    field.set(newInstance, fieldObjectClone);
                    if (dumpClonedClasses && fieldObjectClone != fieldObject) {
                        System.out.println("cloned field>" + field + "  -- of class " + o.getClass());
                    }
                }
            }
        }
        return newInstance;
    }

It needs to be called with null as startWith

Maybe there is a nicer way, but copying from one object to another seems to be 
a nice feature, I think.

Original issue reported on code.google.com by [email protected] on 16 Jul 2013 at 2:17

I would like to ignore certain "instance" fields from my cloning process.

What steps will reproduce the problem?
1. Create a Parent object that contains a List of Child objects.
2. Create a Child object has a reference to its Parent.
3. Parent parent = null;
4. Child child = null;
5. parent.addChild(child);
6. child.setParent(parent);
7. cloner.deepClone(child);

What is the expected output? What do you see instead?
The cloned instance of child has a new copy of parent with a list of copies of 
child.

I would like the cloner to ignore the "parent" field in the child instance and 
not clone it.

What version of the product are you using? 
1.9.0
On what operating system?
Win 7 Enterprise

Please provide any additional information below.
I tried to use the following:
cloner.registerConstant(Child.class, "parent");
But because "parent" is an instance field and not static (i.e. constant) I get 
a NullPointerException.

Original issue reported on code.google.com by [email protected] on 10 Dec 2013 at 10:10

Complimentray cloneOnly method

There is a dontClone method. I would suggest to also do the opposite where you 
specify the only classes that can be cloned.

Original issue reported on code.google.com by [email protected] on 19 Jul 2011 at 10:11

dumpClonedClasses should not use System.out

Possible alternatives:

* Support a "callback" that can be registered on the Cloner instance
* Refactor the System.out calls into methods that a class can override when 
extending Cloner
* Use a logging framework

The first or second I think are preferable as they won't require inclusion of a 
logging framework although something like slf4j could be used such that an end 
user of the library can include the implement of their choice (or none).

Personally though, even with a logging framework I think there is value is the 
first or second as the end user of the library can plug-in something besides 
logging-- like maybe adding functionality to only log if a cloning clones > X 
objects

Original issue reported on code.google.com by [email protected] on 22 May 2014 at 4:53

Feature request: provide ant build.xml

Hi

I'ld be interested in creating a RPM package for cloning. Shortly said, maven 
is a nightmare regarding rpm build.

I'm not familiar with maven, but I was told it can generate ant build.xml files 
through command "mvn ant:ant". Would you mind seing if you can provide those, 
for a maven-independant build?

Thanks,
Rémy

Original issue reported on code.google.com by [email protected] on 13 Mar 2012 at 2:27

Add OSGi Manifest headers

I'm planning on using Cloning in an OSGi environment but I found that the jar 
does not have the necessary headers to do so. Please consider adding the 
necessary manifest headers, or, even easier, add OSGi bundlisation to your 
maven project.

Original issue reported on code.google.com by [email protected] on 19 Sep 2012 at 1:07

Problem cloning enums that override toString()

See attached java file for test code.

This should print 'true' 3 times. Instead it's all 'false'.

Tested with 1.7.9 on windows 7, with java:
Java(TM) SE Runtime Environment (build 1.7.0_05-b05)
Java HotSpot(TM) Client VM (build 23.1-b03, mixed mode, sharing)

Original issue reported on code.google.com by [email protected] on 16 Jul 2012 at 9:31

Attachments:

IllegalArgumentException on clone

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 [email protected] on 18 Dec 2012 at 12:03

Conflict with Cloning jar and Log4j jar.

Hi,

I am using an web-application where i am using the cloning jar in cache 
implementation. Here i am facing an issue like after few minutes of 
transactions the log is not generating and throwing an error:--

log4j:ERROR Could not close 
org.apache.log4j.helpers.CountingQuietWriter@10c8abcd
java.io.IOException: Bad file descriptor

But if i remove the cloning jar, log is working fine. So the cloning jar is 
having a conflict with the log4j jar.

The log4j is working with all other third party jars except this cloning jar.

Can you tell me if this is a bug with the cloning jar? 

The jar versions which i am using are:-

Cloning--1.7.4
log4j--1.2.9

Original issue reported on code.google.com by [email protected] on 12 Dec 2013 at 1:47

API is working on TOMCAT, But failing on Weblogic

What steps will reproduce the problem?
1. Created a deep clone on the object 

What is the expected output? What do you see instead?
Should create the deep clone. Application is crashed.



What version of the product are you using? On what operating system?
1.9.0, on Linux


Please provide any additional information below.
We are using the deepClone on a Hibernate Object, which is working fine on 
Tomcat and Windows OS, but when we deploy same app on Web logic and Unix OS and 
use the page which has the deepclone for 4 or 5 times, it is killing the 
application. And no one can do any thing.

Appreciate your quick soon as matter of urgeny.

Thank you 


Original issue reported on code.google.com by [email protected] on 19 Jun 2014 at 10:16

Collection fast cloners and non-cloned objects

The fast cloners for Sets and Lists should check for a null response from 
cloner.cloneInternal() before attempting to add to the collection as it's 
possible that null would be returned due to ignoredInstances or ignored classes.

The behavior for a Map is a bit more questionable-- but again would think that 
storing a null value for a key would not be the expected result. In addition, 
it's possible the key itself would not be cloned.

Original issue reported on code.google.com by [email protected] on 22 May 2014 at 4:43

java.util.Date is not cloned correctly with the property nullTransient=true

What steps will reproduce the problem?
1. Create an object with a property from the type java.util.Date (or 
java.sql.Date)
2. clone this object
3. the date property is always the value 1-1-1970

What is the expected output? What do you see instead?
A new Date object with the correct date, not 1-1-1970.


What version of the product are you using? On what operating system?
Used version 1.9.0, java 1.6


Please provide any additional information below.

The problem can be sovled with a fastCloner for java.util.date which calls the 
clone() method on date.

An other good option would be to use the clone() method on all classes which 
have implemented the cloneable interface.


Original issue reported on code.google.com by [email protected] on 9 Nov 2012 at 2:34

Callback for "should Clone" check

Support for a callback that can provide a decision on whether an object should 
be cloned or not.

The callback would take the object to clone and return a Boolean:
* true == the object should be cloned
* false == the object should be returned as is
* null == null should be returned instead of cloning or returning the object as 
is

The callback should likely be added in cloneInternal(), after the bulk of the 
should or should not clone decisions are made, such as right before the calls 
to fastClone().

Original issue reported on code.google.com by [email protected] on 22 May 2014 at 4:58

Global cache object being updated inspite of cloning

In my web-application i am keeping a particular object in cache. Now whenever i 
am using this cache in front end i am making a clone and using it.

In the front end i have a checkbox which i can check and its value is contained 
in the object which i am keeping in cache.

In the initial case the checkbox in unchecked. But if i once check it then it 
is remaining as checked even it is coming as cloned object from cache.

This mean that the global cache object is being updated and cloning is not 
happening properly.

Is this a bug in the jar? Are there any provisions to address it?



Original issue reported on code.google.com by [email protected] on 23 Dec 2013 at 3:15

HibernateException "Found shared references to a collection"

I use your project in an JEE/Maven environment with Hibernate and a MySQL-DB. I 
get an error when a collection is involved in my entity-graph:

Caused by: org.hibernate.HibernateException: Found shared references to a 
collection: my.package.model.Line.lineSectionSchedules

In class Line the code is as following:

@OneToMany(mappedBy = "line")
@Getter
@Setter
@Cascade({ CascadeType.ALL })
@OrderColumn(name = "sectionScheduleOrder")
private Collection<SectionSchedule> lineSectionSchedules = new 
ArrayList<SectionSchedule>();

When the list lineSectionSchedules is empty, then everything works as expected.

Any ideas what I make wrong?

Original issue reported on code.google.com by [email protected] on 16 Apr 2013 at 3:32

ConcurrentModificationException issue

What steps will reproduce the problem?
1. when cloner copys a shared object
2. shared object's field is list, and list number changed
3. cloner will get ConcurrentModificationException in fastClone

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

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

Please provide any additional information below.
I found can use CopyOnWriteArrayList to avoid this issue:

in FastClonerArrayList.java

List<Object> entrys = new CopyOnWriteArrayList<Object>();
        if (!al.isEmpty()) {
            entrys.addAll(al);
        }
for (final Object o : entrys) {
}

Original issue reported on code.google.com by [email protected] on 19 May 2014 at 1:01

JPA Clone ISSue

What steps will reproduce the problem?
1.Use JPA Entities 
2.Make a clone of your JPA entity
3.

What is the expected output? What do you see instead?
An object cloned from my JPA entity, but I got an infinity loop of cloning, it 
clone so much class (configuration classes and others uses on mapping)

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

1.8.1

Please provide any additional information below.
It works fine on normal objects, but not on JPA objects (entities) even 
detached entities. 

Original issue reported on code.google.com by [email protected] on 1 Aug 2012 at 1:41

Please fix the issue #16 that is already "Done"

https://code.google.com/p/cloning/issues/detail?id=16

What steps will reproduce the problem?
1. put the cloner lib to tomcat/lib folder
2. create at least two apps that will use cloner
3. the system may fail on cloning because fields will be mixed up

What version of the product are you using? On what operating system?
ubuntu, java 6, 7

Please provide any additional information below.
the fail starts from version 1.8.2 where ObjenesisInstantiationStrategy was 
added (with singleton). 1.8.1 works correctly (this version works without 
ObjenesisInstantiationStrategy).

Original issue reported on code.google.com by [email protected] on 6 Nov 2013 at 1:40

patch for pom.xml update: java 1.6, compiler update, objenesis update...

<project xmlns="http://maven.apache.org/POM/4.0.0" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.sonatype.oss</groupId>
        <artifactId>oss-parent</artifactId>
        <version>5</version>
    </parent>
    <groupId>com.rits</groupId>
    <artifactId>cloning</artifactId>
    <packaging>bundle</packaging>
    <version>1.9.1-SNAPSHOT</version>
    <name>cloning</name>
    <url>https://code.google.com/p/cloning/</url>
    <description><![CDATA[
                The cloning library is a small, open source (Apache
                licensed) Java library which deep-clones objects. The
                objects do not have to implement the Cloneable
                interface. Effectively, this library can clone ANY
                Java object. It can be used i.e. in cache
                implementations, if you don't want the cached object
                to be modified or whenever you want to create a deep
                copy of an object.

                Sample usage:

                You can create a single instance of cloner and use it throughout your application. i.e.
                Cloner cloner=new Cloner();
                ...
                cloner.deepClone(o);

                Please check http://robust-it.co.uk/clone/ for more examples (spring integration, immutable objects etc)
        ]]></description>
    <licenses>
        <license>
            <name>Apache License, Version 2.0</name>
            <url>http://www.apache.org/licenses/LICENSE-2.0</url>
        </license>
    </licenses>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    <scm>
        <connection>scm:git:https://[email protected]/p/cloning/</connection>
        <developerConnection>scm:git:https://[email protected]/p/cloning/</developerConnection>
        <url>https://code.google.com/p/cloning/source/browse/</url>
    </scm>
    <issueManagement>
        <system>Google Code</system>
        <url>https://code.google.com/p/cloning/issues/list</url>
    </issueManagement>
    <build>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.15</version>
                <configuration>
                    <includes>
                        <include>**/Test*.java</include>
                    </includes>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-source-plugin</artifactId>
                <version>2.2.1</version>
                <executions>
                    <execution>
                        <id>attach-sources</id>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-javadoc-plugin</artifactId>
                <version>2.9.1</version>
                <executions>
                    <execution>
                        <id>attach-javadocs</id>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-release-plugin</artifactId>
                <version>2.4.1</version>
            </plugin>
            <plugin>
                <artifactId>maven-repository-plugin</artifactId>
                <version>2.3.1</version>
            </plugin>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.4</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <descriptors>
                        <descriptor>src/main/assembly/dist.xml</descriptor>
                    </descriptors>
                    <descriptorRefs>
                        <descriptorRef>project</descriptorRef>
                    </descriptorRefs>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-bundle-plugin</artifactId>
                <version>2.4.0</version>
                <extensions>true</extensions>
            </plugin>
        </plugins>
    </build>
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.objenesis</groupId>
            <artifactId>objenesis</artifactId>
            <version>1.3</version>
        </dependency>
    </dependencies>
    <profiles>
        <profile>
            <id>sonatype-deploy</id>
            <build>
                <defaultGoal>deploy</defaultGoal>
                <plugins>
                    <plugin>
                        <artifactId>maven-gpg-plugin</artifactId>
                        <version>1.4</version>
                        <executions>
                            <execution>
                                <id>sign-artifacts</id>
                                <phase>verify</phase>
                                <goals>
                                    <goal>sign</goal>
                                </goals>
                                <configuration>
                                    <useAgent>true</useAgent>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>


Original issue reported on code.google.com by [email protected] on 9 Aug 2013 at 7:52

ConcurrentModificationException in FastClonerHashMap

While using cloning-1.7.4 or cloning-1.7.5-SNAPSHOT (from today's trunk), I am 
getting a ConcurrentModificationException error. If I change the execution 
timing of my code by enabling some logging, I do not generally get the 
exception. My application utilizes a single Cloner instance, and calls it very 
rapidly, however, not from multiple threads.

The full exception stack is below, minus the calls from my application:
java.util.ConcurrentModificationException
    at java.util.HashMap$HashIterator.nextEntry(HashMap.java:793)
    at java.util.HashMap$EntryIterator.next(HashMap.java:834)
    at java.util.HashMap$EntryIterator.next(HashMap.java:832)
    at com.rits.cloning.FastClonerHashMap.clone(com.rits.cloning.FastClonerHashMap:20)
    at com.rits.cloning.Cloner.fastClone(com.rits.cloning.Cloner:96)
    at com.rits.cloning.Cloner.cloneInternal(com.rits.cloning.Cloner:360)
    at com.rits.cloning.Cloner.cloneInternal(com.rits.cloning.Cloner:409)
    at com.rits.cloning.Cloner.cloneInternal(com.rits.cloning.Cloner:409)
    at com.rits.cloning.Cloner.deepClone(com.rits.cloning.Cloner:309)

If my inquiry should be going to a mailing list instead, please let me know. I 
looked briefly but I didn't see one off hand.

Thanks,

Greg

Original issue reported on code.google.com by [email protected] on 7 Mar 2011 at 9:02

FastClonerTreeMap Comparator Bug

When cloning TreeMaps or TreeSets of objects that do not implement Comparable, 
a ClassCastException occurs.

This can be fixed by changing FastClonerTreeMap line 19 from:
final TreeMap result = new TreeMap();

to

final TreeMap result = new TreeMap(m.comparator());

This is an issue in two situations:
1) The above mentioned issue where the Map/Set contains objects that do not 
implement Comparable, but the client has passed in a Comparator in the 
constructor of the Map/Set.
2) The Map/Set does contain objects that implement Comparable, but the client 
wishes to order the elements differently with a separate Comparator.  The 
cloned object will iterate over objects in their natural order instead of the 
specified order in the Comparator.  This difference may lead to unintended 
consequences.

Please let me know if there is a better solution to this problem.

Thanks,
Jason Lee

Original issue reported on code.google.com by jasondanlee on 5 Dec 2011 at 10:35

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.