>From Jean-Christophe.Collet@France Thu Jan 16 07:37:07 1997
Date: Thu, 16 Jan 1997 16:28:26 +0100 (MET)
From: Jean-Christophe Collet <Jean-Christophe.Collet@France>
Subject: Odd JDK-1.1 beta2 GregorianCalendar.clone() bug
To: ###@###.###
X-Sun-Text-Type: ascii
Hi Folks,
I just stumbled on a very odd bug with JDK 1.1 beta-2.
Compile this simple program :
---------------------------------------------------------
import java.io.*;
import java.util.*;
class Test {
public static void main(String[] args) {
GregorianCalendar d1, d2, d3;
d1 = new GregorianCalendar(1997,1,16);
d2 = (GregorianCalendar) d1.clone();
d2.set(Calendar.HOUR, 10);
// System.out.println(d2.getTime().toString());
d3 = (GregorianCalendar) d1.clone();
d3.set(Calendar.HOUR, 11);
System.out.println(d1.getTime().toString() +
"\n" + d2.getTime().toString() +
"\n" + d3.getTime().toString());
}
}
---------------------------------------------------------
When you run it you get :
Sun Feb 16 00:00:00 GMT+03:00 1997
Sun Feb 16 11:00:00 GMT+03:00 1997
Sun Feb 16 11:00:00 GMT+03:00 1997
Which meand d2 & d3 reference the same object!!!!
Now, if you just uncomment the System.out.println... line, you get :
Sun Feb 16 10:00:00 GMT+03:00 1997
Sun Feb 16 00:00:00 GMT+03:00 1997
Sun Feb 16 10:00:00 GMT+03:00 1997
Sun Feb 16 11:00:00 GMT+03:00 1997
Which is the correct result.
Any idea about this ?
----------------------------------------------------------------------
Jean-Christophe Collet (aka "Jessie") | Sun Microsystems France
###@###.### | Ingenieur Technico-Commercial