Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 4823811
Votes 3
Synopsis [Fmt-Da] SimpleDateFormat patterns don't allow embedding of some literal punctuation
Category java:classes_text
Reported Against 1.4.1 , kestrel
Release Fixed 7(b38), 1.4.2_18-rev(b13) (Bug ID:2166298) , 5.0u17-rev(b11) (Bug ID:2168901) , 6u12(b01) (Bug ID:2168943) , 1.4.2_20(b01) (Bug ID:2171629) , 5.0u19(b01) (Bug ID:2174426)
State 10-Fix Delivered, bug
Priority: 4-Low
Related Bugs 6772646 , 4300507
Submit Date 25-FEB-2003
Description




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 :
 customer  Windows XP [Version 5.1.2600]

ADDITIONAL OPERATING SYSTEMS :
I think this also happen on Solaris, but I only had the
 customer  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) 
======================================================================
Work Around
(1) Temporarily replace all "-"s in the pattern and strings to be parsed with another delimiter, like "/". The test case given in the Description can be modified to:

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.replace("-", "/")); // modified
        try {
            date = sdf.parse(s.replace("-", "/")); // modified
            System.out.println("DATE 1: " + date + " --> " + date.getTime());
        } catch (ParseException pe) {
            System.out.println("CAUGHT " + pe + ", errorOffset = " +
			       pe.getErrorOffset());
            pe.printStackTrace();
        }
    }
}

This one produces:

DATE 0: 2002-12,83.567
DATE 1: Tue Jan 01 00:13:23 UTC 2002 --> 1009844003567

(2) When creating a SimpleDateFormat, specify Locale.ENGLISH (or Locale.ROOT in JDK 6) explicitly if the format pattern doesn't involve any Arabic strings (e.g., month names).

import java.text.*;
import java.util.*;

public class Test2 {
    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, Locale.ROOT); // modified
        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();
        }
    }
}

This one produces the following as well.

DATE 0: 2002-12,83.567
DATE 1: Tue Jan 01 00:13:23 UTC 2002 --> 1009844003567
Evaluation



Problem exists in all of 1.1.8, 1.2.2, 1.3.1, 1.4, 1.4.1.


======================================================================
Comments
  
  Include a link with my name & email   

Submitted On 23-APR-2004
pdardailler
When are you expecting this bug to be fixed? 


Submitted On 25-JUL-2005
molis1
Can you please comment on when this bug will be fixed?


Submitted On 11-JUL-2007
trey333
Is this bug planning to be fixed? If so, which version will contain the fix?



PLEASE NOTE: JDK6 is formerly known as Project Mustang