Ben, <mailto:[email protected]>  I found your name in the source
code.

 

Thanks for making PDFBox open source with Apache.

 

I am using the PDF parser you wrote; I will be using it in a thread
environment

 

I ran the Findbugs tool (http://findbugs.sourceforge.net/) 

against the package and an issue occurred in :
org.apache.pdfbox.util.DateConverter;

 

It shows this problem in two places.

 

 

[H M STCAL] Call to static DateFormat
[STCAL_INVOKE_ON_STATIC_DATE_FORMAT_INSTANCE]

As the JavaDoc states, DateFormats are inherently unsafe for
multithreaded use. The detector has found a call to an instance of
DateFormat that has been obtained via a static field. This looks
suspicious.

For more information on this see Sun Bug #6231579
<http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6231579>  and Sun
Bug #6178997
<http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6178997> . 

 

There was only one call to the toString*(date) method

 

I changed the following lines to resolve the issue.

 

public DateConverter() {}  // allows the class to be created.

 

     // next I removed the static from the method.

 

 

    public  String toString( Calendar date )

    {

        String retval = null;

        if( date != null )

        {

            StringBuffer buffer = new StringBuffer();

            TimeZone zone = date.getTimeZone();

            long offsetInMinutes = zone.getOffset(
date.getTimeInMillis() )/1000/60;

            long hours = Math.abs( offsetInMinutes/60 );

            long minutes = Math.abs( offsetInMinutes%60 );

            buffer.append( "D:" );

            // this had to be create here, it couldn't be static 

// because of the bug description

            SimpleDateFormat PDF_DATE_FORMAT = new SimpleDateFormat(
"yyyyMMddHHmmss" );

 

            buffer.append( PDF_DATE_FORMAT.format( date.getTime() )

 

 

Lastly, I change the call to the method in COSDictionary.

 

    public void setDate( COSName key, Calendar date )

    {

        setString( key, new DateConverter().toString( date ) );

    }

 

Reply via email to