You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@directory.apache.org by "Tomi Keinonen (JIRA)" <di...@incubator.apache.org> on 2005/09/01 11:58:05 UTC

[jira] Created: (DIRSNICKERS-106) DERGeneralizedTime and DERUTCTime are not thread safe

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
 Assigned to: 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


Re: [jira] Commented: (DIRSNICKERS-106) DERGeneralizedTime and DERUTCTime are not thread safe

Posted by Jérôme Baumgarten <jb...@gmail.com>.
Actually it is the same for java.text.Format and all subclasses.

I also discovered that lately and had to go through all my code to
take care of that.

On 9/1/05, Emmanuel Lecharny (JIRA) <di...@incubator.apache.org> wrote:
>     [ 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
> 
>

[jira] Resolved: (DIRSNICKERS-106) DERGeneralizedTime and DERUTCTime are not thread safe

Posted by "Emmanuel Lecharny (JIRA)" <di...@incubator.apache.org>.
     [ http://issues.apache.org/jira/browse/DIRSNICKERS-106?page=all ]
     
Emmanuel Lecharny resolved DIRSNICKERS-106:
-------------------------------------------

    Resolution: Fixed
     Assign To: Emmanuel Lecharny  (was: Alex Karasulu)

All SimpleDateFormat usage have been synchronized all over the code.



> 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: Emmanuel Lecharny

>
> 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


[jira] Commented: (DIRSNICKERS-106) DERGeneralizedTime and DERUTCTime are not thread safe

Posted by "Emmanuel Lecharny (JIRA)" <di...@incubator.apache.org>.
    [ 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