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

[Fmt-Da] SimpleDateFormat patterns don't allow embedding of some literal punctuation

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 1.3.0, 1.4.1, 5.0
    • Fix Version/s: 7
    • Component/s: core-libs
    • Subcomponent:
    • Resolved In Build:
      b38
    • CPU:
      x86, sparc
    • OS:
      solaris_2.3, windows_xp
    • Verification:
      Verified

      Backports

        Description



        Name: nt126004 Date: 02/25/2003


        FULL PRODUCT VERSION :
        java version "1.4.0"
        Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-b92)
        Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed mode)


        FULL OPERATING SYSTEM VERSION :
        Microsoft Windows XP [Version 5.1.2600]

        ADDITIONAL OPERATING SYSTEMS :
        I think this also happen on Solaris, but I only had the
        IBM JDK to test with there.


        A DESCRIPTION OF THE PROBLEM :
        Because of the "greedy" way the numeric parsing works
        inside SimpleDateFormat.parse, it's not possible to embed
        certain literal characters. Here is an example:

        In Locale "ar_EG" (Arabic Egypt), you can't use literal
        dashes as separators for date components because the first
        dash gets "eaten" as part of parsing the first integer
        (Arabic locales put numeric signs to the right of the
        digits).

        It doesn't help if you surround the dash with 'single
        quotes' in the pattern.


        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        Run the source code provided below. I don't know if you
        have to do something to make sure you have a Locale
        for "ar_EG" installed on your machine.

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        Expect to parse the date into constituent parts, but
        instead get an exception.

        CAUGHT java.text.ParseException: Unparseable date: "2002-
        12,83.567", errorOffset = 5


        ERROR MESSAGES/STACK TRACES THAT OCCUR :
        java.text.ParseException: Unparseable date: "2002-12,83.567"
        at java.text.DateFormat.parse(DateFormat.java:324)
        at org.carpenter.bill.CreTe.demoDateBug(CreTe.java:3093)


        REPRODUCIBILITY :
        This bug can be reproduced always.

        ---------- BEGIN SOURCE ----------
        import java.text.*;
        import java.util.*;
        public class Test {
        public static void main(String[] args) {
        String s = "2002-12,83.567";
                System.out.println("DATE 0: " + s);
                String pattern = "yyyy'-'mm','ss'.'SSS";
                SimpleDateFormat sdf;
                Date date = null;


                Locale.setDefault(new Locale("ar", "EG"));
                sdf = new SimpleDateFormat(pattern);
                try
                {
                    date = sdf.parse(s);
                    System.out.println("DATE 1: " + date + " --> " + date.getTime());
                }
                catch (ParseException pe)
                {
                    System.out.println("CAUGHT " + pe + ", errorOffset = " +
        pe.getErrorOffset());
                    pe.printStackTrace();
                }
        }
        }
        ---------- END SOURCE ----------

        CUSTOMER WORKAROUND :
        I have not found one.
        (Review ID: 181728)
        ======================================================================

          Attachments

            Issue Links

              Activity

                People

                Assignee:
                peytoia Yuka Kamiya (Inactive)
                Reporter:
                nthompsosunw Nathanael Thompson (Inactive)
                Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                  Dates

                  Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: