NullPointerException when saving Document
-----------------------------------------

                 Key: PDFBOX-1125
                 URL: https://issues.apache.org/jira/browse/PDFBOX-1125
             Project: PDFBox
          Issue Type: Bug
          Components: Writing
    Affects Versions: 1.6.0
            Reporter: Per Abich


I am trying to fill out this form(official Norwegian Government form): 
http://www.nav.no/Om+NAV/Skjemaer/Arbeidsgiverskjemaer/L%C3%B8nn+og+personalskjemaer+for+din+bedrift+%28HR%29/Yrkesskade/_attachment/1073746888?_ts=1271f676c80
 

My code looks as follows: 

  public void setKode(InputStream inputStream, String value, OutputStream 
output) throws IOException, COSVisitorException
  {
    PDDocument pdfDocument = PDDocument.load(inputStream);
    if (LOGGER.isInfoEnabled())
    {
      LOGGER.info(pdfDocument.getCurrentAccessPermission().toString());
    }
    PDDocumentCatalog docCatalog = pdfDocument.getDocumentCatalog();
    PDAcroForm acroForm = docCatalog.getAcroForm();
    PDField field = acroForm.getField("beskrivelse");
    if (field != null)
    {
      field.setValue(value);
    } else
    {
      System.err.println("No field found with name:" + "beskrivelse");
    }
    pdfDocument.save(output);
  }


While trying to fill in the field "beskrivelse" (or any other field in this 
form) I get the following stacktrace:

java.lang.NullPointerException
        at java.io.FilterInputStream.close(FilterInputStream.java:155)
        at 
org.apache.pdfbox.pdfwriter.COSWriter.doWriteSignature(COSWriter.java:688)
        at 
org.apache.pdfbox.pdfwriter.COSWriter.visitFromDocument(COSWriter.java:1039)
        at org.apache.pdfbox.cos.COSDocument.accept(COSDocument.java:456)
        at org.apache.pdfbox.pdfwriter.COSWriter.write(COSWriter.java:1360)
        at org.apache.pdfbox.pdmodel.PDDocument.save(PDDocument.java:1121)
        at com.qmplus.PDFTest.App.setKode(App.java:36)
        at com.qmplus.PDFTest.AppTest.test(AppTest.java:35)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at 
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
        at 
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
        at 
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
        at 
org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
        at 
org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
        at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
        at 
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:69)
        at 
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:48)
        at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
        at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
        at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
        at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
        at org.junit.runners.ParentRunner.run(ParentRunner.java:292)
        at 
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
        at 
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
        at 
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
        at 
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
        at 
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
        at 
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

The funny thing is, the output is created and looks to my eyes fine...

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Reply via email to