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

Tilman Hausherr edited comment on PDFBOX-6187 at 4/4/26 12:38 PM:
------------------------------------------------------------------

I can't reproduce it; also the place you mention has a null check since 2018 
(PDFBOX-4235):
{code:java}
            // get the font
            PDFont font = defaultAppearance.getFont();
            if (font == null)
            {
                throw new IllegalArgumentException("font is null, check whether 
/DA entry is incomplete or incorrect");
            }
            if (font.getName().contains("+"))
            {
{code}
Maybe it's the wrong file, or the wrong version? The PDF does have a problem, I 
wonder if it was created by one early version of PDFBox 3.0. Two fonts in the 
font default resources point to fields instead of fonts.
 !screenshot-1.png! 


was (Author: tilman):
I can't reproduce it; also the place you mention has a null check since 2018:
{code:java}
            // get the font
            PDFont font = defaultAppearance.getFont();
            if (font == null)
            {
                throw new IllegalArgumentException("font is null, check whether 
/DA entry is incomplete or incorrect");
            }
            if (font.getName().contains("+"))
            {
{code}
Maybe it's the wrong file, or the wrong version? The PDF does have a problem, I 
wonder if it was created by one early version of PDFBox 3.0. Two fonts in the 
font default resources point to fields instead of fonts.
 !screenshot-1.png! 

>  NullPointerException in AppearanceGeneratorHelper when PDFont.getName() 
> returns null  
> ---------------------------------------------------------------------------------------
>
>                 Key: PDFBOX-6187
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-6187
>             Project: PDFBox
>          Issue Type: Bug
>          Components: AcroForm
>    Affects Versions: 3.0.6 PDFBox
>         Environment: Java 17 (OpenJDK)  
>            Reporter: Joseph Jezerinac
>            Priority: Major
>         Attachments: FailingDocument-sample.pdf, screenshot-1.png
>
>
> When opening a PDF that contains an AcroForm text field whose font resource 
> has no /BaseFont entry, PDFont.getName() returns null. The default AcroForm 
> fixup triggered by getAcroForm() calls refreshAppearances(), which leads to a 
> NullPointerException in
>  AppearanceGeneratorHelper.insertGeneratedAppearance() at line 516, where 
> String.contains() is called on the null return value without a null check.
>  Steps to reproduce:
>  {code:java}                                                                  
>                                                                               
>                                                                               
>                                                      
>   import org.apache.pdfbox.Loader;                                            
>                                                                               
>                                                                               
>                                                       
>   import org.apache.pdfbox.pdmodel.PDDocument;                                
>                                                                               
>                                                                               
>                                                       
>   import org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm;               
>                                                                               
>                                                                               
>                                                       
>   import java.io.File;                    
>                                                                               
>                                                                               
>                                                                               
>                                                       
>   public class PdfBoxNullFontNameTest {                                       
>                                                                               
>                                                                               
>                                                       
>    
>       private static final String PDF_PATH = 
> "/path/to/FailingDocument-sample.pdf";                                        
>                                                                               
>                                                                               
>          
>                                           
>       public static void main(String[] args) throws Exception {
>           File pdf = new File(PDF_PATH);                                      
>                                                                               
>                                                                               
>                                                       
>           PDDocument doc = Loader.loadPDF(pdf);
>           PDAcroForm form = doc.getDocumentCatalog().getAcroForm();           
>                                                                               
>                                                                               
>                                                       
>       }                                       
>   }                                       
>   {code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to