You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by Andrew Munn <an...@nmedia.net> on 2015/04/22 00:38:08 UTC

NullPointer in StandardSecurityHandler

It looks like the StandardProtectionPolicy policy == null here:

 private int computeRevisionNumber() {
        return this.version < 2 && 
!this.policy.getPermissions().hasAnyRevision3PermissionSet()?2:(this.version 
== 5?6:(this.version != 2 && this.version != 3 && 
!this.policy.getPermissions().hasAnyRevision3PermissionSet()?4:3));
    }

java.lang.NullPointerException
	at org.apache.pdfbox.pdmodel.encryption.StandardSecurityHandler.computeRevisionNumber(StandardSecurityHandler.java:129)
	at org.apache.pdfbox.pdmodel.encryption.StandardSecurityHandler.prepareDocumentForEncryption(StandardSecurityHandler.java:332)
	at org.apache.pdfbox.pdfwriter.COSWriter.write(COSWriter.java:1254)
	at org.apache.pdfbox.pdfwriter.COSWriter.write(COSWriter.java:1215)
	at org.apache.pdfbox.pdmodel.PDDocument.save(PDDocument.java:958)
	at org.apache.pdfbox.pdmodel.PDDocument.save(PDDocument.java:930)

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


Re: NullPointer in StandardSecurityHandler

Posted by Tilman Hausherr <TH...@t-online.de>.
Hi,

Fixed. The difference is that you now get an exception telling you what 
to do.

Tilman

Am 22.04.2015 um 08:00 schrieb Tilman Hausherr:
> https://issues.apache.org/jira/browse/PDFBOX-2769
> created.
>
> In the meantime, either follow the instructions at 
> https://pdfbox.apache.org/1.8/cookbook/encryption.html , or call 
> setAllSecurityToBeRemoved(true) before saving your doc.
>
> And yes, your doc is encrypted, but with an empty user psw.
>
> Tilman
>
>
>
> Am 22.04.2015 um 01:37 schrieb Andrew Munn:
>> On Wed, 22 Apr 2015, Tilman Hausherr wrote:
>>
>>> I think I remember seeing this before... happens when calling save 
>>> with some
>>> incomplete encryption settings. Could you please post the shortest 
>>> possible
>>> code that reproduces the error, the version you are using, and 
>>> upload the PDF
>>> you are using (if applicable) somewhere.
>>
>> I'm not trying to do any encryption.  That's the odd part.  Code is just
>> this:
>>
>> public void thisWillFail() {
>>          Path f = Paths.get("c:\\temp\\test.pdf");
>>          try {
>>              PDDocument document = PDDocument.load(f.toFile());
>>              File file = Paths.get("c:\\temp\\fail.pdf").toFile();
>>              try {
>>                  document.save(file); // <-- EXCEPTION
>>              } catch (NullPointerException e) {
>>                  e.printStackTrace();
>>                  System.exit(-123);
>>              }
>>              document.close();
>>          } catch (IOException e) {
>>              e.printStackTrace();
>>          }
>>      }
>>
>> PDF is
>> http://www.optionsclearing.com/market-data/series/ess-record-layout.pdf
>>
>> Thanks
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
>> For additional commands, e-mail: users-help@pdfbox.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


Re: NullPointer in StandardSecurityHandler

Posted by Tilman Hausherr <TH...@t-online.de>.
https://issues.apache.org/jira/browse/PDFBOX-2769
created.

In the meantime, either follow the instructions at https://pdfbox.apache.org/1.8/cookbook/encryption.html , or call setAllSecurityToBeRemoved(true) before saving your doc.

And yes, your doc is encrypted, but with an empty user psw.

Tilman



Am 22.04.2015 um 01:37 schrieb Andrew Munn:
> On Wed, 22 Apr 2015, Tilman Hausherr wrote:
>
>> I think I remember seeing this before... happens when calling save with some
>> incomplete encryption settings. Could you please post the shortest possible
>> code that reproduces the error, the version you are using, and upload the PDF
>> you are using (if applicable) somewhere.
>
> I'm not trying to do any encryption.  That's the odd part.  Code is just
> this:
>
> public void thisWillFail() {
>          Path f = Paths.get("c:\\temp\\test.pdf");
>          try {
>              PDDocument document = PDDocument.load(f.toFile());
>              File file = Paths.get("c:\\temp\\fail.pdf").toFile();
>              try {
>                  document.save(file); // <-- EXCEPTION
>              } catch (NullPointerException e) {
>                  e.printStackTrace();
>                  System.exit(-123);
>              }
>              document.close();
>          } catch (IOException e) {
>              e.printStackTrace();
>          }
>      }
>
> PDF is
> http://www.optionsclearing.com/market-data/series/ess-record-layout.pdf
>
> Thanks
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


Re: NullPointer in StandardSecurityHandler

Posted by Andrew Munn <an...@nmedia.net>.
...and I'm running latest 2.0.0 snapshot

On Tue, 21 Apr 2015, Andrew Munn wrote:

> On Wed, 22 Apr 2015, Tilman Hausherr wrote:
> 
> > I think I remember seeing this before... happens when calling save with some
> > incomplete encryption settings. Could you please post the shortest possible
> > code that reproduces the error, the version you are using, and upload the PDF
> > you are using (if applicable) somewhere.
> 
> 
> I'm not trying to do any encryption.  That's the odd part.  Code is just 
> this:
> 
> public void thisWillFail() {
>         Path f = Paths.get("c:\\temp\\test.pdf");
>         try {
>             PDDocument document = PDDocument.load(f.toFile());
>             File file = Paths.get("c:\\temp\\fail.pdf").toFile();
>             try {
>                 document.save(file); // <-- EXCEPTION
>             } catch (NullPointerException e) {
>                 e.printStackTrace();
>                 System.exit(-123);
>             }
>             document.close();
>         } catch (IOException e) {
>             e.printStackTrace();
>         }
>     }
> 
> PDF is 
> http://www.optionsclearing.com/market-data/series/ess-record-layout.pdf
> 
> Thanks
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


Re: NullPointer in StandardSecurityHandler

Posted by Andrew Munn <an...@nmedia.net>.
On Wed, 22 Apr 2015, Tilman Hausherr wrote:

> I think I remember seeing this before... happens when calling save with some
> incomplete encryption settings. Could you please post the shortest possible
> code that reproduces the error, the version you are using, and upload the PDF
> you are using (if applicable) somewhere.


I'm not trying to do any encryption.  That's the odd part.  Code is just 
this:

public void thisWillFail() {
        Path f = Paths.get("c:\\temp\\test.pdf");
        try {
            PDDocument document = PDDocument.load(f.toFile());
            File file = Paths.get("c:\\temp\\fail.pdf").toFile();
            try {
                document.save(file); // <-- EXCEPTION
            } catch (NullPointerException e) {
                e.printStackTrace();
                System.exit(-123);
            }
            document.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

PDF is 
http://www.optionsclearing.com/market-data/series/ess-record-layout.pdf

Thanks


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


Re: NullPointer in StandardSecurityHandler

Posted by Tilman Hausherr <TH...@t-online.de>.
I think I remember seeing this before... happens when calling save with 
some incomplete encryption settings. Could you please post the shortest 
possible code that reproduces the error, the version you are using, and 
upload the PDF you are using (if applicable) somewhere.

But if my memory is correct, the solution won't get the error away, 
instead there would be an IllegalStateException with a meaningful error 
message.

For an example about how to do encryption, see 
TestSymmetricKeyEncryption.java, and 
https://pdfbox.apache.org/1.8/cookbook/encryption.html

Tilman

Am 22.04.2015 um 00:38 schrieb Andrew Munn:
> It looks like the StandardProtectionPolicy policy == null here:
>
>   private int computeRevisionNumber() {
>          return this.version < 2 &&
> !this.policy.getPermissions().hasAnyRevision3PermissionSet()?2:(this.version
> == 5?6:(this.version != 2 && this.version != 3 &&
> !this.policy.getPermissions().hasAnyRevision3PermissionSet()?4:3));
>      }
>
> java.lang.NullPointerException
> 	at org.apache.pdfbox.pdmodel.encryption.StandardSecurityHandler.computeRevisionNumber(StandardSecurityHandler.java:129)
> 	at org.apache.pdfbox.pdmodel.encryption.StandardSecurityHandler.prepareDocumentForEncryption(StandardSecurityHandler.java:332)
> 	at org.apache.pdfbox.pdfwriter.COSWriter.write(COSWriter.java:1254)
> 	at org.apache.pdfbox.pdfwriter.COSWriter.write(COSWriter.java:1215)
> 	at org.apache.pdfbox.pdmodel.PDDocument.save(PDDocument.java:958)
> 	at org.apache.pdfbox.pdmodel.PDDocument.save(PDDocument.java:930)
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org