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

java.text.DateFormat parsing error with Locale.German

XMLWordPrintable

      FULL PRODUCT VERSION :
      java 9.0.1

      ADDITIONAL OS VERSION INFORMATION :
      Linux saber-ubuntu 4.4.0-45-generic #66-Ubuntu SMP Wed Oct 19 14:12:37 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux


      A DESCRIPTION OF THE PROBLEM :
      java.text.DateFormat parsing error with Locale.German on dates with DD MMM YYYY format.
      e.g., parsing "31 Dez 2005" with format "dd MMM yyyy"
      with
      DateFormat.parseObject();

      See more details in attached test case.

      REGRESSION. Last worked in version 8u152

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the attached test case

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The test case pass
      ACTUAL -
      The test case throws a null pointer exception, as the parsing fails.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      package edu.utsa.cs.test4incomp;

      import java.text.DateFormat;
      import java.text.DateFormatSymbols;
      import java.text.ParsePosition;
      import java.text.SimpleDateFormat;
      import java.util.Calendar;
      import java.util.Locale;

      import org.junit.Test;

      import junit.framework.TestCase;

      public class TestLocaleParse extends TestCase{
      @Test
      public void testLocaleParse(){

              String germanVal = "31 Dez 2005";
              String germanPattern = "dd MMM yyyy";
              
              Calendar cal = (Calendar)parse(germanVal, germanPattern, Locale.GERMAN);
              cal.getTime();
      }


      protected Object parse(String value, String pattern, Locale locale) {

              DateFormatSymbols symbols = new DateFormatSymbols(locale);
              DateFormat formatter = new SimpleDateFormat(pattern, symbols);
              formatter.setLenient(false);
              
              ParsePosition pos = new ParsePosition(0);
              formatter.parseObject(value, pos);
              if (pos.getErrorIndex() > -1) {
                  return null;
              }
              return ((DateFormat)formatter).getCalendar();

          }
      }

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

            psonal Pallavi Sonal (Inactive)
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: