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

Parsing a date in arabic locale throws exception in JDK 9 but passes in JDK8

XMLWordPrintable

      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 :
      Linux SELAB-SERVER2 4.13.0-26-generic #29~16.04.2-Ubuntu SMP Tue Jan 9 22:00:44 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

      A DESCRIPTION OF THE PROBLEM :
      It works in JDK8, but produces a bug in JDK9.


      REGRESSION. Last worked in version 8u151

      ADDITIONAL REGRESSION INFORMATION:
      java version "1.8.0_151"
      Java(TM) SE Runtime Environment (build 1.8.0_151-b12)
      Java HotSpot(TM) 64-Bit Server VM (build 25.151-b12, mixed mode)

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Pass test

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      java.text.ParseException: Unparseable date: "س, جمادى الأولى 23, 1436"
      at java.text.DateFormat.parse(DateFormat.java:366)
      at edu.utsa.cs.test4incomp.test3.parseDate(test3.java:47)
      at edu.utsa.cs.test4incomp.test3.formatWithArabicLocale(test3.java:31)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:498)
      at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
      at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
      at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
      at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
      at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
      at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
      at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
      at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
      at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
      at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
      at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
      at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
      at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
      at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
      at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)



      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import static org.junit.Assert.*;

      import java.io.File;
      import java.net.MalformedURLException;
      import java.net.URISyntaxException;
      import java.net.URL;
      import java.security.CodeSource;
      import java.text.ParseException;
      import java.text.SimpleDateFormat;
      import java.util.Calendar;
      import java.util.Locale;
      import java.util.TimeZone;

      import org.junit.Assert;
      import org.junit.Test;

      public class test3 {

      public static Locale en = new Locale("en");
      public static Locale ar = new Locale("ar");



      @Test
      public void formatWithArabicLocale() throws ParseException {


      Calendar uCal = parseDate("1436-5-23", "y-M-d", ar);
      uCal = parseDate("س, جمادى الأولى 23, 1436", "E, MMMM d, y", ar);
      assertEquals(" 'س, جمادى الأولى 23, 1436' should parse using 'E, MMMM d, y' format",
      "1436-5-23",
      String.format("%d-%d-%d", uCal.get(Calendar.YEAR), uCal.get(Calendar.MONTH) + 1, uCal.get(Calendar.DAY_OF_MONTH)));

      }

      public Calendar parseDate(String dateText, String fmt, Locale l) throws ParseException {
      Calendar uCal = Calendar.getInstance();

      SimpleDateFormat dateFormat = new SimpleDateFormat(fmt, l);
      dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
      dateFormat.setCalendar(uCal);
      uCal.set(Calendar.YEAR, 1420);
      dateFormat.set2DigitYearStart(uCal.getTime());

      uCal.setTime(dateFormat.parse(dateText));
      return uCal;
      }
      }

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

      SUPPORT :
      YES

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

              Created:
              Updated:
              Resolved: