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

False representation of certain years with certain locales using java.time.format.DateTimeFormatter.ofPattern(String)

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Not an Issue
    • Affects Version/s: 9.0.1
    • Fix Version/s: None
    • Component/s: core-libs
    • Subcomponent:
    • CPU:
      x86_64
    • OS:
      windows

      Description

      FULL PRODUCT VERSION :
      java version "9.0.1"
      Java(TM) SE Runtime Environment (build 9.0.1+11)
      Java HotSpot(TM) 64-Bit Server VM (build 9.0.1+11, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 10.0.16299.248]

      A DESCRIPTION OF THE PROBLEM :
      Sorry for reporting in the wrong category, there was none for the java.time package.

      The problem relates to java.time.format.DateTimeFormatter.ofPattern(String) with several locales like german, french and italian. Formatting a first-day-of-a-year-date for certain years (eg: 2017-01-01, 2021-01-01, 2022-01-01, ...) with the ofPattern("YYYY")-method results in displaying the wrong year. It happens with 105 locales. Tested with Java 8 and 9.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Execute the test case code.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Printing:
      Count: 0
      ACTUAL -
      nn: 2017-01-01 != 16-01-01
      lv: 2017-01-01 != 16-01-01
      en_GG: 2017-01-01 != 16-01-01
      sv_SE: 2017-01-01 != 16-01-01
      dsb_DE: 2017-01-01 != 16-01-01
      sk: 2017-01-01 != 16-01-01
      sv: 2017-01-01 != 16-01-01
      cs: 2017-01-01 != 16-01-01
      el: 2017-01-01 != 16-01-01
      se_NO: 2017-01-01 != 16-01-01
      pl_PL: 2017-01-01 != 16-01-01
      es_ES: 2017-01-01 != 16-01-01
      bg_BG: 2017-01-01 != 16-01-01
      nb_SJ: 2017-01-01 != 16-01-01
      hsb_DE: 2017-01-01 != 16-01-01
      lb_LU: 2017-01-01 != 16-01-01
      no_NO_NY: 2017-01-01 != 16-01-01
      sv_FI: 2017-01-01 != 16-01-01
      no: 2017-01-01 != 16-01-01
      en_GB: 2017-01-01 != 16-01-01
      fr_MC: 2017-01-01 != 16-01-01
      en_JE: 2017-01-01 != 16-01-01
      gsw_CH: 2017-01-01 != 16-01-01
      en_AT: 2017-01-01 != 16-01-01
      et: 2017-01-01 != 16-01-01
      gd_GB: 2017-01-01 != 16-01-01
      en_NL: 2017-01-01 != 16-01-01
      gsw_FR: 2017-01-01 != 16-01-01
      hu_HU: 2017-01-01 != 16-01-01
      fi: 2017-01-01 != 16-01-01
      et_EE: 2017-01-01 != 16-01-01
      fy_NL: 2017-01-01 != 16-01-01
      de_CH: 2017-01-01 != 16-01-01
      fr_FR: 2017-01-01 != 16-01-01
      nl_NL: 2017-01-01 != 16-01-01
      sk_SK: 2017-01-01 != 16-01-01
      gv_IM: 2017-01-01 != 16-01-01
      fr_BE: 2017-01-01 != 16-01-01
      nb_NO: 2017-01-01 != 16-01-01
      it_SM: 2017-01-01 != 16-01-01
      fr_RE: 2017-01-01 != 16-01-01
      fi_FI: 2017-01-01 != 16-01-01
      ca_FR: 2017-01-01 != 16-01-01
      fr_GP: 2017-01-01 != 16-01-01
      hu: 2017-01-01 != 16-01-01
      fr_CH: 2017-01-01 != 16-01-01
      de_BE: 2017-01-01 != 16-01-01
      cs_CZ: 2017-01-01 != 16-01-01
      ca_ES: 2017-01-01 != 16-01-01
      rm_CH: 2017-01-01 != 16-01-01
      fr: 2017-01-01 != 16-01-01
      de: 2017-01-01 != 16-01-01
      ksh_DE: 2017-01-01 != 16-01-01
      se_FI: 2017-01-01 != 16-01-01
      fr_LU: 2017-01-01 != 16-01-01
      ca_IT: 2017-01-01 != 16-01-01
      no_NO: 2017-01-01 != 16-01-01
      ca_AD: 2017-01-01 != 16-01-01
      de_LU: 2017-01-01 != 16-01-01
      it_CH: 2017-01-01 != 16-01-01
      de_DE: 2017-01-01 != 16-01-01
      en_DK: 2017-01-01 != 16-01-01
      lt_LT: 2017-01-01 != 16-01-01
      it_IT: 2017-01-01 != 16-01-01
      nn_NO: 2017-01-01 != 16-01-01
      pl: 2017-01-01 != 16-01-01
      se_SE: 2017-01-01 != 16-01-01
      it: 2017-01-01 != 16-01-01
      da_DK: 2017-01-01 != 16-01-01
      wae_CH: 2017-01-01 != 16-01-01
      en_BE: 2017-01-01 != 16-01-01
      fo_DK: 2017-01-01 != 16-01-01
      en_CH: 2017-01-01 != 16-01-01
      fo_FO: 2017-01-01 != 16-01-01
      ast_ES: 2017-01-01 != 16-01-01
      fr_MQ: 2017-01-01 != 16-01-01
      is_IS: 2017-01-01 != 16-01-01
      lt: 2017-01-01 != 16-01-01
      fur_IT: 2017-01-01 != 16-01-01
      en_SE: 2017-01-01 != 16-01-01
      fr_GF: 2017-01-01 != 16-01-01
      is: 2017-01-01 != 16-01-01
      gsw_LI: 2017-01-01 != 16-01-01
      ca: 2017-01-01 != 16-01-01
      kw_GB: 2017-01-01 != 16-01-01
      en_DE: 2017-01-01 != 16-01-01
      en_FI: 2017-01-01 != 16-01-01
      pt_PT: 2017-01-01 != 16-01-01
      eu_ES: 2017-01-01 != 16-01-01
      el_GR: 2017-01-01 != 16-01-01
      en_FJ: 2017-01-01 != 16-01-01
      de_LI: 2017-01-01 != 16-01-01
      smn_FI: 2017-01-01 != 16-01-01
      de_AT: 2017-01-01 != 16-01-01
      nl: 2017-01-01 != 16-01-01
      ca_ES_VALENCIA: 2017-01-01 != 16-01-01
      da: 2017-01-01 != 16-01-01
      gl_ES: 2017-01-01 != 16-01-01
      en_IM: 2017-01-01 != 16-01-01
      en_GI: 2017-01-01 != 16-01-01
      nl_BE: 2017-01-01 != 16-01-01
      cy_GB: 2017-01-01 != 16-01-01
      sv_AX: 2017-01-01 != 16-01-01
      nb: 2017-01-01 != 16-01-01
      br_FR: 2017-01-01 != 16-01-01
      Count: 105

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      public class DateFormatTest {
          public static void main(String[] args) {
              int iYear = 2017;
              long count = java.util.stream.Stream.of(java.util.Locale.getAvailableLocales())
                      .filter((java.util.Locale locale) -> {
                  java.time.LocalDate date = java.time.LocalDate.of(iYear, java.time.Month.JANUARY, 1);
                  String strYear = date.format(java.time.format.DateTimeFormatter.ofPattern("YYYY")
                          .withLocale(locale));

                  if (!strYear.equals(String.valueOf(iYear))) {
                      System.out.println(locale + ": " + date + " != "
                              + date.format(java.time.format.DateTimeFormatter.ofPattern("YY-MM-dd")
                                      .withLocale(locale)));
                  }
                  return !strYear.equals(String.valueOf(iYear));
              }).count();
              System.out.println("Count: " + count);
          }
      }
      ---------- END SOURCE ----------

        Attachments

          Activity

            People

            • Assignee:
              psonal Pallavi Sonal
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: