JDK-6609357 : (cal) HOUR and HOUR_OF_DAY fields of Calender Object are not syncronized in Java 1.5
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util:i18n
  • Affected Version: 5.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2007-09-26
  • Updated: 2010-07-29
  • Resolved: 2007-10-16
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.5.0_06"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05
Java HotSpot(TM) Client VM (build 1.5.0_06-b05, mixed mode, sharing)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]

A DESCRIPTION OF THE PROBLEM :
The HOUR and HOUR_OF_DAY fields of the calendar object are not synchronized when we try to roll any one of the fields. This is happening only in Java 1.5 but not in earlier versions.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the sample test case in JDK 1.5 and observe the output.
Run the same test case in JDK 1.4 and observe the output. Its synchronized in JDK1.4 but not in JDK 1.5

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The HOUR and  HOUR_OF_DAY fields should be synchronized. If the HOUR_OF_DAY field value is 20 after rolling, the HOUR field value shoule be 8
ACTUAL -
The HOUR field is not getting updated when we try to roll the HOUR_OF_DAY field of the calendar object.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.text.DateFormat;
import java.text.SimpleDateFormat;

import java.util.Calendar;
import java.util.Date;

public class DateTest
{
  public static void main (String[] args)
  {
    DateFormat f = new SimpleDateFormat("h");
    Calendar c = Calendar.getInstance();
    c.roll(Calendar.HOUR_OF_DAY, true);
    Date date = c.getTime();
    f.setCalendar(c);
    System.out.println(date);
    System.out.println(f.format(date));
    System.out.println("=================");
    System.out.println(c.get(Calendar.HOUR));
    System.out.println(c.get(Calendar.HOUR_OF_DAY));
  }
}

---------- END SOURCE ----------

Comments
EVALUATION This problem was fixed in 1.5.0_07.
16-10-2007