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

Hungarian Locale causes date formatter to throw ParseDateException

XMLWordPrintable

      FULL PRODUCT VERSION :
      java version "1.6.0_10"
      Java(TM) SE Runtime Environment (build 1.6.0_10-b33)
      Java HotSpot(TM) Server VM (build 11.0-b15, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      Linux ha28c1n6 2.4.21-47.0.1.ELhugemem #1 SMP Fri Oct 13 17:48:02 EDT 2006 i686 i686 i386 GNU/Linux
      Microsoft Windows XP [Version 5.1.2600]

      A DESCRIPTION OF THE PROBLEM :
      On Hungarian machines with a Locale of “hu_HU” we find that the symbol in date formatters for am/pm which is normally “a” becomes “x” and parsing the date causes a ParseException

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      see attached test case

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Should format properly.
      ACTUAL -
      causes a parsing exception on all AM parsing

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.text.ParseException;
      import java.text.SimpleDateFormat;
      import java.util.Locale;

      import junit.framework.Assert;

      import org.junit.Test;
      import org.junit.internal.runners.JUnit4ClassRunner;
      import org.junit.runner.RunWith;

      @RunWith(JUnit4ClassRunner.class)
      public class TestDate {

          private final static String TIME = "1:00:00 am";
          private final static String TIME_FORMAT = "h:m:s a";
          
          @Test
          public void testUkDateParsing() throws ParseException
          {
              Locale.setDefault(Locale.UK);
              SimpleDateFormat formatter = new SimpleDateFormat(TIME_FORMAT);
              formatter.parse(TIME);
              Assert.assertEquals(TIME_FORMAT, formatter.toLocalizedPattern());
          }
          
          @Test
          public void testHungarianDateParsing() throws ParseException
          {
              Locale.setDefault(new Locale("hu", "HU"));
              SimpleDateFormat formatter = new SimpleDateFormat(TIME_FORMAT);
              formatter.parse(TIME);
              Assert.assertEquals(TIME_FORMAT, formatter.toLocalizedPattern());
          }
          
      }

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

            jennyh Jenny Huang (Inactive)
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: