JDK-4028518 : clone() method in java.util.Calendar not working properly
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util
  • Affected Version: 1.1
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • OS: solaris_2.5
  • CPU: sparc
  • Submitted: 1997-01-28
  • Updated: 2014-01-07
  • Resolved: 1998-01-13
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.2.0 1.2beta3Fixed
Related Reports
Relates :  
Description

Name: mc57594			Date: 01/28/97


When modifying a cloned object instance that extends
  Calendar (e.g. GregorianCalendar), those modifications will also
  be reflected in the original object instance.  Could this be an
  example of shallow cloning?  Example to follow:

import java.util.GregorianCalendar ;

public class CalendarBug {

   public static void main(String[] args)
   {
      GregorianCalendar cal1 = new GregorianCalendar() ;
      GregorianCalendar cal2 = (GregorianCalendar) cal1.clone() ;

      printdate(cal1, "cal1: ") ;
      printdate(cal2, "cal2 - cloned(): ") ;
      cal2.add(GregorianCalendar.DATE, 1) ;
      printdate(cal1, "cal1 after adding 1 day:") ;
      printdate(cal2, "cal2 should be unmodified:") ;
   }

   private static void printdate(GregorianCalendar cal, String string)
   {
      System.out.print(string);
      System.out.print("" + cal.get(GregorianCalendar.MONTH)) ;
      int date = cal.get(GregorianCalendar.DATE) + 1 ;
      System.out.print("/" + date) ;
      System.out.println("/" + cal.get(GregorianCalendar.YEAR)) ;
   }
}
======================================================================

Comments
The regression test for this bug doesn't detect the bug.
07-01-2014

CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: 1.2beta3 FIXED IN: 1.2beta3 INTEGRATED IN: 1.2beta3
14-06-2004

EVALUATION We could not reproduce this bug, but we went ahead and checked in a regression test for it anyway.
11-06-2004

WORK AROUND Name: mc57594 Date: 01/28/97 None ======================================================================
11-06-2004