Uploaded image for project: 'PDFBox'
  1. PDFBox
  2. PDFBOX-402

Bug when using PDF Box in a threaded environment.


    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.2.0
    • Component/s: Utilities
    • Labels:
    • Environment:
      Multi Thread usage, like in an Application Server using PDFBox to parse documents.


      I will be using PDFBox 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

      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 ) ); }


        1. patch
          3 kB
          Sean Bridges

          Issue Links



              • Assignee:
                peter_lenahan@ibi.com Peter_Lenahan@ibi.com
              • Votes:
                0 Vote for this issue
                1 Start watching this issue


                • Created: