JDK-6610534 : HttpCookies.parse can't set MaxAge correctly, when locale is Locale.JAPAN.
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.net
  • Affected Version: 6
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2007-09-27
  • Updated: 2010-08-19
  • Resolved: 2009-06-25
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7
7Resolved
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.6.0_02"
Java(TM) SE Runtime Environment (build 1.6.0_02-b06)
Java HotSpot(TM) Client VM (build 1.6.0_02-b06, mixed mode, sharing)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]

A DESCRIPTION OF THE PROBLEM :
When Locale is Locale.JAPAN, HttpCookie can't parse Expires and always set MaxAge to 0.
I show the detail below:

1. HTTP server sends cookie like:

  Set-Cookie: id=1234; Expires=Sat, 01-Sep-2007 05:03:41 GMT;

2. HttpCookie.parse method is called, and then expiryDate2DeltaSecond method is called for parsing Expires attribute.

    private final static String NETSCAPE_COOKIE_DATE_FORMAT = "EEE',' dd-MMM-yyyy HH:mm:ss 'GMT'";

    private long expiryDate2DeltaSeconds(String dateString) {
        SimpleDateFormat df = new SimpleDateFormat(NETSCAPE_COOKIE_DATE_FORMAT);

        df.setTimeZone(TimeZone.getTimeZone("GMT"));

        try {
            Date date = df.parse(dateString);
            return (date.getTime() - whenCreated) / 1000;
        } catch (Exception e) {
            e.printStackTrace();
            return 0;
        }
    }
    
3. When Locale is Locale.JAPAN, EEE of SimpleDateFormat is indicated by Kanji character and MMM is indicated by number like:

  [SEE char.txt attachment], 31-8-2007 05:03:41 GMT

  Therefore, df.parse throws ParseException.

  java.text.ParseException: Unparseable date: "Sat, 01-Sep-2007 05:03:41 GMT"
        at java.text.DateFormat.parse(DateFormat.java:337)
        at java.net.HttpCookie.expiryDate2DeltaSeconds(HttpCookie.java:1049)

4. Exception is caught by catch clase, and return value is 0. i.e. MaxAge is 0.


For fixing bug, instantiate SimpleDateFormat with Locale explicitly.

        SimpleDateFormat df = new SimpleDateFormat(NETSCAPE_COOKIE_DATE_FORMAT,
                                                   Locale.US);




REPRODUCIBILITY :
This bug can be reproduced always.