directory-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Emmanuel Lecharny (JIRA)" <directory-...@incubator.apache.org>
Subject [jira] Commented: (DIRSNICKERS-106) DERGeneralizedTime and DERUTCTime are not thread safe
Date Thu, 01 Sep 2005 10:36:07 GMT
    [ http://issues.apache.org/jira/browse/DIRSNICKERS-106?page=comments#action_12320775 ]


Emmanuel Lecharny commented on DIRSNICKERS-106:
-----------------------------------------------

Bloody sh*t ! That's a good catch !

SimpleDateFormat has been documented as not thread safe only in jdk1.4 doco. 

It uses a Calendar internally, which is not threadsafe. 

We must browse the whole code to find out every places where SimpleDateFormat is used as a
static member.

Thanks Tomi !

> DERGeneralizedTime and DERUTCTime are not  thread safe
> ------------------------------------------------------
>
>          Key: DIRSNICKERS-106
>          URL: http://issues.apache.org/jira/browse/DIRSNICKERS-106
>      Project: Directory ASN1
>         Type: Bug
>   Components: BER Runtime
>     Versions: 0.3.0
>  Environment: Java version "1.5.0_04", Windows XP.
>     Reporter: Tomi Keinonen
>     Assignee: Alex Karasulu

>
> Both classes DERGeneralizedTime and DERUTCTime include a static definition for date format:
>  private static final SimpleDateFormat dateFormat = new SimpleDateFormat( "yyMMddHHmmss'Z'"
);
> Static attribute is used by method:
>     public Date getDate()
>     	throws ParseException
>     {
>         String string = byteArrayToString( value );
>         return dateFormat.parse( string );
>     }
> This fails when multiple threads access getDate concurrently. Calling dateFormat.parse
is not synchronized and class SimpleDateFormat is not  internally syncronized. JavaDoc for
SimpleDateFormat says:
> "Date formats are not synchronized. It is recommended to create separate format instances
for each thread. If multiple threads access a format concurrently, it must be synchronized
externally." 
> This causes not to be able to parse multiple DER streams concurrently and limits their
usage in server environment.
> Without synchronization dateFormat.parse causes unpredictable errors. For example:
> ---
>  java.lang.NumberFormatException: For input string: ".1212"
> 	at java.lang.NumberFormatException.forInputString(Unknown Source)
> 	at java.lang.Long.parseLong(Unknown Source)
> 	at java.lang.Long.parseLong(Unknown Source)
> 	at java.text.DigitList.getLong(Unknown Source)
> 	at java.text.DecimalFormat.parse(Unknown Source)
> 	at java.text.SimpleDateFormat.subParse(Unknown Source)
> 	at java.text.SimpleDateFormat.parse(Unknown Source)
> 	at java.text.DateFormat.parse(Unknown Source)
> 	at org.apache.asn1.der.DERGeneralizedTime.getDate(DERGeneralizedTime.java:68)
> ---
> java.lang.NumberFormatException: For input string: ""
> 	at java.lang.NumberFormatException.forInputString(Unknown Source)
> 	at java.lang.Long.parseLong(Unknown Source)
> 	at java.lang.Long.parseLong(Unknown Source)
> 	at java.text.DigitList.getLong(Unknown Source)
> 	at java.text.DecimalFormat.parse(Unknown Source)
> 	at java.text.SimpleDateFormat.subParse(Unknown Source)
> 	at java.text.SimpleDateFormat.parse(Unknown Source)
> 	at java.text.DateFormat.parse(Unknown Source)
> 	at org.apache.asn1.der.DERGeneralizedTime.getDate(DERGeneralizedTime.java:68)
> ---
> java.lang.ArrayIndexOutOfBoundsException: -1
> 	at java.text.DigitList.fitsIntoLong(Unknown Source)
> 	at java.text.DecimalFormat.parse(Unknown Source)
> 	at java.text.SimpleDateFormat.subParse(Unknown Source)
> 	at java.text.SimpleDateFormat.parse(Unknown Source)
> 	at java.text.DateFormat.parse(Unknown Source)
> 	at org.apache.asn1.der.DERGeneralizedTime.getDate(DERGeneralizedTime.java:68)
> ---

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


Mime
View raw message