akshayyn / cloning

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

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

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
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 boersmas...@gmail.com on 9 Nov 2012 at 2:34

GoogleCodeExporter commented 8 years ago
Hi, what do you mean "date" property? Can you provide a code sample?

Original comment by kostas.k...@googlemail.com on 7 Dec 2012 at 8:22

GoogleCodeExporter commented 8 years ago

    public static void main(String[] args) {
        Date original = new Date();
        Cloner cloner = new Cloner();
        cloner.setNullTransient(true);
        Date clone = cloner.deepClone(original);

        // I expect this to be true, but is is false.
        System.out.println(original.getTime() == clone.getTime());
    }

Original comment by erikhorl...@gmail.com on 20 Jan 2013 at 9:31

GoogleCodeExporter commented 8 years ago
Ok, I don't see anything wrong with that. It should be false since Date uses 
this field:

    private transient long fastTime;

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

GoogleCodeExporter commented 8 years ago
ok,looks like it works correctly, closing the issue

Original comment by kostas.k...@googlemail.com on 24 Mar 2013 at 10:44