[ 
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:06 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):
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 (actually so will setting fonts = null). 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
>             Fix For: 2.0.0
>
>         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)

Reply via email to