You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pdfbox.apache.org by "John Hewson (JIRA)" <ji...@apache.org> on 2014/09/03 19:03:53 UTC

[jira] [Comment Edited] (PDFBOX-2310) codeToGID NPE

    [ https://issues.apache.org/jira/browse/PDFBOX-2310?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14120090#comment-14120090 ] 

John Hewson edited comment on PDFBOX-2310 at 9/3/14 5:03 PM:
-------------------------------------------------------------

This problem is caused by PDFBox clearing a cache inside a PDFont object:

{code}
if (fonts != null)
{
    for(PDFont font : fonts.values())
    {
        font.clear();
    }
    fonts.clear();
    fonts = null;
}
{code}

The whole PDFont#clear() concept doesn't actually achieve anything, the subsequent Map#clear() call will free the font objects for garbage collection anyway. Likewise calling fonts.clear() before setting fonts = null does nothing. It's like somebody was trying to write a C++ destructor, but of course that's not needed in Java. The code above can be reduced to:

{code}
fonts = null;
{code}

Which will achieve the exact same thing as the garbage collector will take care of everything else. Likewise for similar code for PDXObject.

I'm going to remove all of these redundant clear() methods.


was (Author: jahewson):
{code}
if (fonts != null)
{
    for(PDFont font : fonts.values())
    {
        font.clear();
    }
    fonts.clear();
    fonts = null;
}
{code}

The whole PDFont#clear() concept doesn't actually achieve anything, the subsequent Map#clear() call will free the font objects for garbage collection anyway. Likewise calling fonts.clear() before setting fonts = null does nothing. It's like somebody was trying to write a C++ destructor, but of course that's not needed in Java. The code above can be reduced to:

{code}
fonts = null;
{code}

Which will achieve the exact same thing as the garbage collector will take care of everything else. Likewise for similar code for PDXObject.

I'm going to remove all of these redundant clear() methods.

> codeToGID NPE
> -------------
>
>                 Key: PDFBOX-2310
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-2310
>             Project: PDFBox
>          Issue Type: Bug
>          Components: PDModel
>    Affects Versions: 2.0.0
>            Reporter: simon steiner
>            Assignee: John Hewson
>         Attachments: expected.pdf
>
>
> java -jar ~/pdf-box-svn/app/target/pdfbox-app-2.0.0-SNAPSHOT.jar PDFToImage expected.pdf
> Exception in thread "main" java.lang.NullPointerException
> 	at org.apache.pdfbox.pdmodel.font.PDType0Font.codeToGID(PDType0Font.java:306)



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)