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

Bug when using PDF Box in a threaded environment.

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 1.2.0
    • Utilities
    • None
    • Multi Thread usage, like in an Application Server using PDFBox to parse documents.

    Description

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

      Attachments

        1. patch
          3 kB
          Sean Bridges

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved: