JDK-6178071 : (cal) REGRESSION: GregorianCalendar.set(Calendar.HOUR, ...) has no effect
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util:i18n
  • Affected Version: 5.0,5.0u5
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: linux,solaris_10,windows_xp
  • CPU: x86,sparc
  • Submitted: 2004-10-12
  • Updated: 2010-07-29
  • Resolved: 2005-09-19
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 JDK 6
5.0u7Fixed 6 b53Fixed
Related Reports
Duplicate :  
Duplicate :  
Duplicate :  
Relates :  
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.5.0-rc"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-rc-b63)
Java HotSpot(TM) Client VM (build 1.5.0-rc-b63, mixed mode, sharing)

A DESCRIPTION OF THE PROBLEM :
Setting the 'HOUR' field of a freshly created GregorianCalendar has no effect on the Date value returned by a subsequent call to getTime().
You have to call getTime() at least once before setting the 'HOUR' field to make it work.
There is no problem with setting the 'HOUR_OF_DAY' field

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile and run the test code under jdk 1.5 , watch the output to stdout.

It does work in prior releases of the VM (at least up to 1.4.2_04)

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Date: Thu Jan 01 01:00:00 CET 2004

ACTUAL -
Date: Thu Jan 01 00:00:00 CET 2004


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.util.*;

public class CalTest {
   public CalTest() {}

   public static void main(String[] args) {
      GregorianCalendar cal = new GregorianCalendar(2004, 0,1);
//      activating this line makes it work!
//      cal.getTime();
      cal.set(Calendar.HOUR, 1);
      System.out.println("Date: " + cal.getTime());
   }
}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Call getTime() in advance or use HOUR_OF_DAY instead.

Release Regression From : 1.4.2
The above release value was the last known release where this 
bug was known to work. Since then there has been a regression.
###@###.### 10/12/04 21:56 GMT

Comments
EVALUATION In the constructors, HOUR and AM_PM will be set from the hourOfDay value.
12-09-2005

EVALUATION When 4846659 was fixed, the HOUR and AM_PM fields were aggregated in the same way as other date fields to support the semantic of the field resolution spec in the Calendar class. But this semantic wasn't compatible with the previous GregorianCalendar implementation. The HOUR field needs to be treated special. ###@###.### 10/14/04 09:40 GMT
14-10-2004