You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pdfbox.apache.org by "Peter_Lenahan@ibi.com (JIRA)" <ji...@apache.org> on 2009/01/24 06:19:59 UTC
[jira] Created: (PDFBOX-402) Bug when using PDF Box in a threaded
environment.
Bug when using PDF Box in a threaded environment.
-------------------------------------------------
Key: PDFBOX-402
URL: https://issues.apache.org/jira/browse/PDFBOX-402
Project: PDFBox
Issue Type: Bug
Components: Utilities
Environment: Multi Thread usage, like in an Application Server using PDFBox to parse documents.
Reporter: Peter_Lenahan@ibi.com
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 ) );
}
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Updated: (PDFBOX-402) Bug when using PDF Box in a threaded
environment.
Posted by "Sean Bridges (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/PDFBOX-402?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Sean Bridges updated PDFBOX-402:
--------------------------------
Attachment: patch
This is a pretty serious issue. This patch fixes this issue and another issue of the same type in in the same file.
> Bug when using PDF Box in a threaded environment.
> -------------------------------------------------
>
> Key: PDFBOX-402
> URL: https://issues.apache.org/jira/browse/PDFBOX-402
> Project: PDFBox
> Issue Type: Bug
> Components: Utilities
> Environment: Multi Thread usage, like in an Application Server using PDFBox to parse documents.
> Reporter: Peter_Lenahan@ibi.com
> Attachments: patch
>
>
> 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 ) );
> }
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.