You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pdfbox.apache.org by "Martin Hilpert (JIRA)" <ji...@apache.org> on 2010/08/31 11:09:55 UTC

[jira] Created: (PDFBOX-807) NullPointerException in StandardSecurityHandler.java:261

NullPointerException in StandardSecurityHandler.java:261
--------------------------------------------------------

                 Key: PDFBOX-807
                 URL: https://issues.apache.org/jira/browse/PDFBOX-807
             Project: PDFBox
          Issue Type: Bug
          Components: PDModel
    Affects Versions: 1.2.1
         Environment: JDK 1.6.0_21, Windows XP 32 Bit.
            Reporter: Martin Hilpert
            Priority: Blocker


I like to add text to a PDF and used the example code AddMessageToEachPage.java to do this. I added decryption to support encrypted docs:

                doc = PDDocument.load(sourceFile);
                if (doc.isEncrypted()) {
                    doc.decrypt(ownerPwd);
                }


When my document is encrypted, the decryption succeeds without error message, but for such encrypted docs, when callinf doc.save(), a NullPointerException occurs:

-----------------------------------------
    java.lang.NullPointerException
    	at org.apache.pdfbox.pdmodel.encryption.StandardSecurityHandler.prepareDocumentForEncryption(StandardSecurityHandler.java:261)
    	at org.apache.pdfbox.pdfwriter.COSWriter.write(COSWriter.java:1013)
    	at org.apache.pdfbox.pdmodel.PDDocument.save(PDDocument.java:911)
    	at org.apache.pdfbox.pdmodel.PDDocument.save(PDDocument.java:892)
-----------------------------------------------------------------


-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (PDFBOX-807) NullPointerException in StandardSecurityHandler.java:261

Posted by "Adam Nichols (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/PDFBOX-807?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12905631#action_12905631 ] 

Adam Nichols commented on PDFBOX-807:
-------------------------------------

If possible, you should use the latest code from SVN.  I'm using the latest code and I noticed the lines don't match up to your stacktrace.  Also, if you can provide an example file so we can duplicate the issue and debug, that might help us get this resolved.

If your goal is to save an unencrypted PDF, you'll want to call doc.setAllSecurityToBeRemoved(true); before saving.

If your goal is to save the PDF in its encrypted form, then I believe what you have should work.  You call decrypt(String) which calls openProtection() and that should pull get the securityHandler.  In fact, it must be getting a securityHandler, as the following line would throw a NPE if it was null.

I think I'll need an example document to be able to sort this on out.  As far as I can tell, the only times the securityHandler can be modified is in protect() and openProtection().  So I'm not sure what's going on here.  I'm sure a quick trip down debugger lane will shed some light on the problem though.

> NullPointerException in StandardSecurityHandler.java:261
> --------------------------------------------------------
>
>                 Key: PDFBOX-807
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-807
>             Project: PDFBox
>          Issue Type: Bug
>          Components: PDModel
>    Affects Versions: 1.2.1
>         Environment: JDK 1.6.0_21, Windows XP 32 Bit.
>            Reporter: Martin Hilpert
>            Priority: Blocker
>
> I like to add text to a PDF and used the example code AddMessageToEachPage.java to do this. I added decryption to support encrypted docs:
>                 doc = PDDocument.load(sourceFile);
>                 if (doc.isEncrypted()) {
>                     doc.decrypt(ownerPwd);
>                 }
> When my document is encrypted, the decryption succeeds without error message, but for such encrypted docs, when callinf doc.save(), a NullPointerException occurs:
> -----------------------------------------
>     java.lang.NullPointerException
>     	at org.apache.pdfbox.pdmodel.encryption.StandardSecurityHandler.prepareDocumentForEncryption(StandardSecurityHandler.java:261)
>     	at org.apache.pdfbox.pdfwriter.COSWriter.write(COSWriter.java:1013)
>     	at org.apache.pdfbox.pdmodel.PDDocument.save(PDDocument.java:911)
>     	at org.apache.pdfbox.pdmodel.PDDocument.save(PDDocument.java:892)
> -----------------------------------------------------------------

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (PDFBOX-807) NullPointerException in StandardSecurityHandler.java:261

Posted by "Andrea Vacondio (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/PDFBOX-807?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12929058#action_12929058 ] 

Andrea Vacondio commented on PDFBOX-807:
----------------------------------------

This can actually be reproduced always using the boudled Decrypt utility (but you have to fix PDFBOX-888 before being able to run it) and trying to decrypt any encrypted document providing an owner password. Calling doc.setAllSecurityToBeRemoved(true) before saving fixed the issue.
What happen I think is that MH tried to create a simple decrypt class following the provided example (like me) with a NPE as result.

Here is a stack trace taken running a test with pdfbox 1.4.0-SNAPSHOT revision 1032087. 
java.lang.NullPointerException
	at org.apache.pdfbox.pdmodel.encryption.StandardSecurityHandler.prepareDocumentForEncryption(StandardSecurityHandler.java:261)
	at org.apache.pdfbox.pdfwriter.COSWriter.write(COSWriter.java:1018)
	at org.apache.pdfbox.pdmodel.PDDocument.save(PDDocument.java:911)
	at org.apache.pdfbox.pdmodel.PDDocument.save(PDDocument.java:892)
	at org.apache.pdfbox.Decrypt.decrypt(Decrypt.java:153)
	at org.apache.pdfbox.Decrypt.main(Decrypt.java:57)
	at org.apache.pdfbox.DecryptTest.testMain(DecryptTest.java:11)
	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)




> NullPointerException in StandardSecurityHandler.java:261
> --------------------------------------------------------
>
>                 Key: PDFBOX-807
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-807
>             Project: PDFBox
>          Issue Type: Bug
>          Components: PDModel
>    Affects Versions: 1.2.1
>         Environment: JDK 1.6.0_21, Windows XP 32 Bit.
>            Reporter: MH
>            Priority: Blocker
>
> I like to add text to a PDF and used the example code AddMessageToEachPage.java to do this. I added decryption to support encrypted docs:
>                 doc = PDDocument.load(sourceFile);
>                 if (doc.isEncrypted()) {
>                     doc.decrypt(ownerPwd);
>                 }
> When my document is encrypted, the decryption succeeds without error message, but for such encrypted docs, when callinf doc.save(), a NullPointerException occurs:
> -----------------------------------------
>     java.lang.NullPointerException
>     	at org.apache.pdfbox.pdmodel.encryption.StandardSecurityHandler.prepareDocumentForEncryption(StandardSecurityHandler.java:261)
>     	at org.apache.pdfbox.pdfwriter.COSWriter.write(COSWriter.java:1013)
>     	at org.apache.pdfbox.pdmodel.PDDocument.save(PDDocument.java:911)
>     	at org.apache.pdfbox.pdmodel.PDDocument.save(PDDocument.java:892)
> -----------------------------------------------------------------

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.