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

Formatting a date in arabic locale shows different output than JDK 8

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 :
      When I use java.util.*, there produces a bug. It works on JDK8, but fails on 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 -
      1436-5-23
      ACTUAL -
      ١٤٣٦-٥-٢٣

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      org.junit.ComparisonFailure: {1436,5,23} should format to '1436-05-23' using 'y-M-d' expected:<[1436-5-23]> but was:<[١٤٣٦-٥-٢٣]>
      at org.junit.Assert.assertEquals(Assert.java:115)
      at edu.utd.cs.testjdk.test.formatWithArabicLocale(test.java:37)
      at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.base/java.lang.reflect.Method.invoke(Method.java:564)
      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:538)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:760)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:460)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:206)



      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      package edu.utd.cs.testjdk;

      import static org.junit.Assert.assertEquals;

      import java.io.File;
      import java.io.IOException;
      import java.text.SimpleDateFormat;
      import java.util.Calendar;
      import java.util.GregorianCalendar;
      import java.util.Locale;
      import java.util.TimeZone;

      import org.apache.commons.io.FileUtils;
      import org.junit.Before;
      import org.junit.Test;




      public class test{

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



      @Test
      public void formatWithArabicLocale() {



      assertEquals("{1436,5,23} should format to '1436-05-23' using 'y-M-d'", "1436-5-23",
      formatDate(ar, "y-M-d"));
      }


      public String formatDate(Locale l, String fmt) {
      Calendar cal = Calendar.getInstance();
      cal.set(1436, 4, 23, 12, 19, 44);
      return formatDate(cal, l, fmt);
      }

      public String formatDate(Calendar cal, Locale l, String fmt) {
      SimpleDateFormat dateFormat = new SimpleDateFormat(fmt, l);
      dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
      dateFormat.setCalendar(cal);
      return dateFormat.format(cal.getTime());
      }


      }
      ---------- 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: