Author: tilman Date: Thu Jul 16 20:30:12 2015 New Revision: 1691444 URL: http://svn.apache.org/r1691444 Log: PDFBOX-2852: remove unused assignments PDFBOX-2888: set allSecurityToBeRemoved to false when protect() is called and log a warning
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java?rev=1691444&r1=1691443&r2=1691444&view=diff ============================================================================== --- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java (original) +++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java Thu Jul 16 20:30:12 2015 @@ -930,7 +930,7 @@ public class PDDocument implements Close */ public static PDDocument load(InputStream input, String password, boolean useScratchFiles) throws IOException { - RandomAccessRead source = null; + RandomAccessRead source; if (useScratchFiles) { source = new RandomAccessBufferedFileInputStream(input); @@ -962,7 +962,7 @@ public class PDDocument implements Close public static PDDocument load(InputStream input, String password, InputStream keyStore, String alias, boolean useScratchFiles) throws IOException { - RandomAccessRead source = null; + RandomAccessRead source; if (useScratchFiles) { source = new RandomAccessBufferedFileInputStream(input); @@ -1160,18 +1160,27 @@ public class PDDocument implements Close } /** - * Protects the document with the protection policy pp. The document content will be really encrypted when it will - * be saved. This method only marks the document for encryption. + * Protects the document with a protection policy. The document content will be really + * encrypted when it will be saved. This method only marks the document for encryption. It also + * calls {@link setAllSecurityToBeRemoved(false)} if it was set to true previously and logs a + * warning. * * @see org.apache.pdfbox.pdmodel.encryption.StandardProtectionPolicy * @see org.apache.pdfbox.pdmodel.encryption.PublicKeyProtectionPolicy - * + * * @param policy The protection policy. - * + * * @throws IOException if there isn't any suitable security handler. */ public void protect(ProtectionPolicy policy) throws IOException { + if (isAllSecurityToBeRemoved()) + { + LOG.warn("do not call setAllSecurityToBeRemoved(true) before calling protect(), " + + "as protect() implies setAllSecurityToBeRemoved(false)"); + setAllSecurityToBeRemoved(false); + } + if (!isEncrypted()) { encryption = new PDEncryption();