Author: tilman Date: Mon Apr 7 14:01:17 2025 New Revision: 1924904 URL: http://svn.apache.org/viewvc?rev=1924904&view=rev Log: PDFBOX-5660: Sonar fix
Modified: pdfbox/branches/3.0/pdfbox/src/test/java/org/apache/pdfbox/encryption/TestPublicKeyEncryption.java Modified: pdfbox/branches/3.0/pdfbox/src/test/java/org/apache/pdfbox/encryption/TestPublicKeyEncryption.java URL: http://svn.apache.org/viewvc/pdfbox/branches/3.0/pdfbox/src/test/java/org/apache/pdfbox/encryption/TestPublicKeyEncryption.java?rev=1924904&r1=1924903&r2=1924904&view=diff ============================================================================== --- pdfbox/branches/3.0/pdfbox/src/test/java/org/apache/pdfbox/encryption/TestPublicKeyEncryption.java (original) +++ pdfbox/branches/3.0/pdfbox/src/test/java/org/apache/pdfbox/encryption/TestPublicKeyEncryption.java Mon Apr 7 14:01:17 2025 @@ -161,18 +161,16 @@ class TestPublicKeyEncryption */ @ParameterizedTest @MethodSource("keyLengths") - void testProtectionError(int keyLength) throws Exception + void testProtectionError(int keyLength) throws IOException { PublicKeyProtectionPolicy policy = new PublicKeyProtectionPolicy(); policy.addRecipient(recipient1); policy.setEncryptionKeyLength(keyLength); document.protect(policy); - PDDocument encryptedDoc = null; - try + File file = save("testProtectionError"); + try (PDDocument encryptedDoc = reload(file, password2, getKeyStore(keyStore2))) { - File file = save("testProtectionError"); - encryptedDoc = reload(file, password2, getKeyStore(keyStore2)); assertTrue(encryptedDoc.isEncrypted()); fail("No exception when using an incorrect decryption key"); } @@ -181,13 +179,6 @@ class TestPublicKeyEncryption String msg = ex.getMessage(); assertTrue(msg.contains("serial-#: rid 2 vs. cert 3"), "not the expected exception: " + msg); } - finally - { - if (encryptedDoc != null) - { - encryptedDoc.close(); - } - } }