Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8229471

Calendar under a specific timezone changes HOUR field when MILLISECOND field is changed

    Details

      Description

      ADDITIONAL SYSTEM INFORMATION :
      Windows 10, Java 64
      the issue is reproducible on Java 7_u25 and java 8_221

      A DESCRIPTION OF THE PROBLEM :
      If you have a Calendar set to a specific timezone (e.g. "Europe/Budapest"), and you change its MILLISECOND field, the hour field will be incorrectly changed as well.

      Work-around: performing a get on the HOUR field, before modifying the MILLISECOND filed will prevent the bug.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      TimeZone tz = TimeZone.getTimeZone("Europe/Budapest");
      Calendar calendar = Calendar.getInstance();
      // Work-around: uncomment this line to prevent the java Calendar bug
      // System.out.println("HOUR: " + calendar.get(Calendar.HOUR));
      calendar.set(Calendar.MILLISECOND, 0);
      System.out.println("HOUR: " + calendar.get(Calendar.HOUR));
      System.out.println("MINUTE: " + calendar.get(Calendar.MINUTE));
      System.out.println("SECOND: " + calendar.get(Calendar.SECOND));
      System.out.println("MILLISECOND: " + calendar.get(Calendar.MILLISECOND));


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Setting the MILLISECOND field won't change the HOUR field
      ACTUAL -
      Setting the MILLISECOND field changes the HOUR field

      ---------- BEGIN SOURCE ----------
      import java.util.Calendar;
      import java.util.TimeZone;

      public class TestCalendar {

      /**
      * @param args
      */
      public static void main(String[] args) {

      TimeZone tz = TimeZone.getTimeZone("Europe/Budapest");
      Calendar calendar = Calendar.getInstance();
      // Work-around: uncomment this line to prevent the java Calendar bug
      // System.out.println("HOUR: " + calendar.get(Calendar.HOUR));
      calendar.set(Calendar.MILLISECOND, 0);
      System.out.println("HOUR: " + calendar.get(Calendar.HOUR));
      System.out.println("MINUTE: " + calendar.get(Calendar.MINUTE));
      System.out.println("SECOND: " + calendar.get(Calendar.SECOND));
      System.out.println("MILLISECOND: " + calendar.get(Calendar.MILLISECOND));
      }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      See source code commented out line

      FREQUENCY : always


        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                naoto Naoto Sato
                Reporter:
                webbuggrp Webbug Group
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: