JDK-4026300 : Gregorian Calendar clone problem
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util
  • Affected Version: 1.1
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: solaris_2.5,solaris_2.5.1
  • CPU: generic,sparc
  • Submitted: 1997-01-16
  • Updated: 1997-10-23
  • Resolved: 1997-10-23
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
1.1 1.1fcsFixed
Related Reports
Duplicate :  
Relates :  
Description
 
>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


Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: generic FIXED IN: 1.1fcs INTEGRATED IN: 1.1fcs
14-06-2004

EVALUATION Calendar.clone was incorrect
11-06-2004

WORK AROUND
11-06-2004

SUGGESTED FIX
11-06-2004

PUBLIC COMMENTS
10-06-2004