You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Harry Levinson (Created) (JIRA)" <ji...@apache.org> on 2012/02/27 20:16:46 UTC

[jira] [Created] (LANG-789) SerializationUtils clone method fails to perform some deep cloning

SerializationUtils clone method fails to perform some deep cloning
------------------------------------------------------------------

                 Key: LANG-789
                 URL: https://issues.apache.org/jira/browse/LANG-789
             Project: Commons Lang
          Issue Type: Bug
          Components: lang.*
    Affects Versions: 3.1
         Environment: Windows 7, Java 7 (1.7.0_03), Apache Commons Lang 3.1, NetBeans 7.1
            Reporter: Harry Levinson


SerializationUtils clone method fails to perform some deep cloning of at least some objects containing Externalizable subobjects.

Here is the @version text from the SerializationUtils.java source file:

SerializationUtils.java 1199718 2011-11-09 12:43:20Z sebb $


To reproduce possible bug:

1. Create two classes (let's call them Parent and Child) and mark both as "implements Externalizable".

2. Write required Externalizable methods readExternal and writeExternal

3. Make Child a private member/field of Parent

4. Write code to override toString if necessary for Parent and Child

5. Create a separate Java class to test creation and cloning of Parent and Child 

6. In the test class write to code to do this:
a. Create a Parent object
b. Create a Child object
c. Attach Child to Parent via setter
d. Print out Parent object
e. Use SerializationUtils.clone() to clone Parent (call it ParentClone)
f. Print ParentClone

7. Compare print output of Parent and ParentClone, observe that ParentClone does not contain Child object


--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (LANG-789) SerializationUtils clone method fails to perform some deep cloning

Posted by "Marcos Vinícius da Silva (Commented JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-789?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13219747#comment-13219747 ] 

Marcos Vinícius da Silva commented on LANG-789:
-----------------------------------------------

I tested this on Windows 7 Sun JDK 1.7.0_03 and Ubuntu 10.04 Sun JDK 1.6.0.26, and worked fine. I used this test case:

{code}
    public void testInnerClassImplementsExternalizable() {
        ExternalizableParent parent = new ExternalizableParent("test");
        ExternalizableParent parentClone = SerializationUtils.clone(parent);
        
        assertEquals(parent.toString(), parentClone.toString());
    }
    
    private static final class ExternalizableParent implements Serializable, Externalizable {
        private ExternalizableChild child;

        public ExternalizableParent() {}
        
        public ExternalizableParent(String value) {
            child = new ExternalizableChild(value);
        }
        
        @Override
        public String toString() {
            return child.value;
        }

        public void readExternal(ObjectInput in) throws IOException,
                ClassNotFoundException {
            child = (ExternalizableChild)in.readObject();
        }

        public void writeExternal(ObjectOutput out) throws IOException {
            out.writeObject(child);
        }
    }
    
    private static final class ExternalizableChild implements Serializable, Externalizable {
        public String value;

        public ExternalizableChild() {}
        
        public ExternalizableChild(String value) {
            this.value = value;
        }

        public void readExternal(ObjectInput in) throws IOException,
                ClassNotFoundException {
            value = (String)in.readObject();
        }

        public void writeExternal(ObjectOutput out) throws IOException {
            out.writeObject(value);
        }
    }
{code}

Are you doing something different?
                
> SerializationUtils clone method fails to perform some deep cloning
> ------------------------------------------------------------------
>
>                 Key: LANG-789
>                 URL: https://issues.apache.org/jira/browse/LANG-789
>             Project: Commons Lang
>          Issue Type: Bug
>          Components: lang.*
>    Affects Versions: 3.1
>         Environment: Windows 7, Java 7 (1.7.0_03), Apache Commons Lang 3.1, NetBeans 7.1
>            Reporter: Harry Levinson
>              Labels: ,, clone,, externalizable,, serializable
>
> SerializationUtils clone method fails to perform some deep cloning of at least some objects containing Externalizable subobjects.
> Here is the @version text from the SerializationUtils.java source file:
> SerializationUtils.java 1199718 2011-11-09 12:43:20Z sebb $
> To reproduce possible bug:
> 1. Create two classes (let's call them Parent and Child) and mark both as "implements Externalizable".
> 2. Write required Externalizable methods readExternal and writeExternal
> 3. Make Child a private member/field of Parent
> 4. Write code to override toString if necessary for Parent and Child
> 5. Create a separate Java class to test creation and cloning of Parent and Child 
> 6. In the test class write to code to do this:
> a. Create a Parent object
> b. Create a Child object
> c. Attach Child to Parent via setter
> d. Print out Parent object
> e. Use SerializationUtils.clone() to clone Parent (call it ParentClone)
> f. Print ParentClone
> 7. Compare print output of Parent and ParentClone, observe that ParentClone does not contain Child object

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

[jira] [Closed] (LANG-789) SerializationUtils clone method fails to perform some deep cloning

Posted by "Harry Levinson (Closed) (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LANG-789?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Harry Levinson closed LANG-789.
-------------------------------

    Resolution: Not A Problem

Thanks Marcos, closing this issue now.

It turned out to be a bug in my code elsewhere, and not the clone "bug" issue I submitted.

I was able to run a version of your code that ran fine. Also fixed my own code and disabled the clone workaround I developed for the child class, all works fine now.

Thanks again for looking at this, sorry to waste your time!

                
> SerializationUtils clone method fails to perform some deep cloning
> ------------------------------------------------------------------
>
>                 Key: LANG-789
>                 URL: https://issues.apache.org/jira/browse/LANG-789
>             Project: Commons Lang
>          Issue Type: Bug
>          Components: lang.*
>    Affects Versions: 3.1
>         Environment: Windows 7, Java 7 (1.7.0_03), Apache Commons Lang 3.1, NetBeans 7.1
>            Reporter: Harry Levinson
>              Labels: ,, clone,, externalizable,, serializable
>
> SerializationUtils clone method fails to perform some deep cloning of at least some objects containing Externalizable subobjects.
> Here is the @version text from the SerializationUtils.java source file:
> SerializationUtils.java 1199718 2011-11-09 12:43:20Z sebb $
> To reproduce possible bug:
> 1. Create two classes (let's call them Parent and Child) and mark both as "implements Externalizable".
> 2. Write required Externalizable methods readExternal and writeExternal
> 3. Make Child a private member/field of Parent
> 4. Write code to override toString if necessary for Parent and Child
> 5. Create a separate Java class to test creation and cloning of Parent and Child 
> 6. In the test class write to code to do this:
> a. Create a Parent object
> b. Create a Child object
> c. Attach Child to Parent via setter
> d. Print out Parent object
> e. Use SerializationUtils.clone() to clone Parent (call it ParentClone)
> f. Print ParentClone
> 7. Compare print output of Parent and ParentClone, observe that ParentClone does not contain Child object

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira