JDK-6791927 : Wrong Locale in HttpCookie::expiryDate2DeltaSeconds
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.net
  • Affected Version: 6,6u10
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2009-01-09
  • Updated: 2011-03-08
  • Resolved: 2011-03-08
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
7 b48Fixed
Related Reports
Duplicate :  
Relates :  
Description
FULL PRODUCT VERSION :
C:\Programme\Java\jdk1.6.0_11\bin>java -version
java version "1.6.0_11"
Java(TM) SE Runtime Environment (build 1.6.0_11-b03)
Java HotSpot(TM) Client VM (build 11.0-b16, mixed mode, sharing)

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

A DESCRIPTION OF THE PROBLEM :
Class: java.net.HttpCookie
Method: private long expiryDate2DeltaSeconds(String dateString)

the method has following implementation:

    SimpleDateFormat df =
        new SimpleDateFormat(NETSCAPE_COOKIE_DATE_FORMAT);
    df.setTimeZone(TimeZone.getTimeZone("GMT"));

so it's using the default Location (in gemany the Locale for germany)

BUT:
the expire attribute for a cookie is given in english or  like that:
Sat, ....

this causes the "df.parse(dateString);" in an exception


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Use the handling cookie framework in a none US Locale and get a Cookie with an expires value in english format

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
the

        try {
            Date date = df.parse(dateString);
            return (date.getTime() - whenCreated) / 1000;
        } catch (Exception e) {
            return 0;
        }

shouldn't run in exception block
ACTUAL -
the exception block is called, so the method returns the "exception" value

ERROR MESSAGES/STACK TRACES THAT OCCUR :
exception isn't thrown, but the function returns 0 instead of the long value

REPRODUCIBILITY :
This bug can be reproduced always.

CUSTOMER SUBMITTED WORKAROUND :
don't know - you made the HttpCookie final

maybe help would be:

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

Comments
EVALUATION Good catch. Indeed the Locale should be specifically added since cookies have to conform to US date format. Will fix as soon as possible.
27-01-2009