Author: tilman
Date: Mon Jun 15 08:27:52 2026
New Revision: 1935334
Log:
PDFBOX-5660: Sonar fix
Modified:
pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/encryption/TestPublicKeyEncryption.java
pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/pdfparser/TestBaseParser.java
pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/common/TestEmbeddedFiles.java
pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/font/TestFontEmbedding.java
Modified:
pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/encryption/TestPublicKeyEncryption.java
==============================================================================
---
pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/encryption/TestPublicKeyEncryption.java
Mon Jun 15 08:05:09 2026 (r1935333)
+++
pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/encryption/TestPublicKeyEncryption.java
Mon Jun 15 08:27:52 2026 (r1935334)
@@ -36,6 +36,7 @@ import org.apache.pdfbox.text.PDFTextStr
import org.junit.After;
import org.junit.Assert;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import org.junit.Before;
import org.junit.Test;
@@ -99,11 +100,10 @@ public class TestPublicKeyEncryption
@Before
public void setUp() throws Exception
{
- if (Cipher.getMaxAllowedKeyLength("AES") != Integer.MAX_VALUE)
- {
- // we need strong encryption for these tests
- fail("JCE unlimited strength jurisdiction policy files are not
installed");
- }
+ // we need strong encryption for these tests
+ assertEquals("JCE unlimited strength jurisdiction policy files are not
installed",
+ Integer.MAX_VALUE, Cipher.getMaxAllowedKeyLength("AES"));
+
permission1 = new AccessPermission();
permission1.setCanAssembleDocument(false);
@@ -163,12 +163,10 @@ public class TestPublicKeyEncryption
policy.setEncryptionKeyLength(keyLength);
document.protect(policy);
- PDDocument encryptedDoc = null;
File file = save("testProtectionError");
try
{
- encryptedDoc = reload(file, password2, getKeyStore(keyStore2));
- Assert.assertTrue(encryptedDoc.isEncrypted());
+ reload(file, password2, getKeyStore(keyStore2));
fail("No exception when using an incorrect decryption key");
}
catch (IOException ex)
@@ -177,13 +175,6 @@ public class TestPublicKeyEncryption
Assert.assertTrue("not the expected exception: " + msg,
msg.contains("serial-#: rid 2 vs. cert 3"));
}
- finally
- {
- if (encryptedDoc != null)
- {
- encryptedDoc.close();
- }
- }
}
Modified:
pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/pdfparser/TestBaseParser.java
==============================================================================
---
pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/pdfparser/TestBaseParser.java
Mon Jun 15 08:05:09 2026 (r1935333)
+++
pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/pdfparser/TestBaseParser.java
Mon Jun 15 08:27:52 2026 (r1935334)
@@ -22,7 +22,6 @@
package org.apache.pdfbox.pdfparser;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
import java.io.IOException;
import java.io.InputStream;
@@ -48,10 +47,5 @@ public class TestBaseParser
{
assertEquals("Missing root object specification in trailer.",
exception.getMessage());
}
- catch (Exception exception)
- {
- fail("Unexpected Exception");
- }
-
}
}
Modified:
pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/common/TestEmbeddedFiles.java
==============================================================================
---
pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/common/TestEmbeddedFiles.java
Mon Jun 15 08:05:09 2026 (r1935333)
+++
pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/common/TestEmbeddedFiles.java
Mon Jun 15 08:27:52 2026 (r1935334)
@@ -38,37 +38,30 @@ public class TestEmbeddedFiles extends T
{
PDEmbeddedFile embeddedFile = null;
boolean ok = false;
- try
- {
- PDDocument doc =
PDDocument.load(TestEmbeddedFiles.class.getResourceAsStream(
- "null_PDComplexFileSpecification.pdf"));
+ PDDocument doc =
PDDocument.load(TestEmbeddedFiles.class.getResourceAsStream(
+ "null_PDComplexFileSpecification.pdf"));
- PDDocumentCatalog catalog = doc.getDocumentCatalog();
- PDDocumentNameDictionary names = catalog.getNames();
- assertEquals("expected two files", 2,
names.getEmbeddedFiles().getNames().size());
- PDEmbeddedFilesNameTreeNode embeddedFiles =
names.getEmbeddedFiles();
+ PDDocumentCatalog catalog = doc.getDocumentCatalog();
+ PDDocumentNameDictionary names = catalog.getNames();
+ assertEquals("expected two files", 2,
names.getEmbeddedFiles().getNames().size());
+ PDEmbeddedFilesNameTreeNode embeddedFiles = names.getEmbeddedFiles();
- PDComplexFileSpecification spec =
embeddedFiles.getNames().get("non-existent-file.docx");
+ PDComplexFileSpecification spec =
embeddedFiles.getNames().get("non-existent-file.docx");
- if (spec != null)
- {
- embeddedFile = spec.getEmbeddedFile();
- ok = true;
- }
- //now test for actual attachment
- spec = embeddedFiles.getNames().get("My first attachment");
- assertNotNull("one attachment actually exists", spec);
- assertEquals("existing file length", 17660,
spec.getEmbeddedFile().getLength());
- spec = embeddedFiles.getNames().get("non-existent-file.docx");
- assertNotNull(spec);
- assertNull(spec.getFile());
- assertNull(spec.getEmbeddedFile());
- doc.close();
- }
- catch (NullPointerException e)
+ if (spec != null)
{
- assertNotNull("null pointer exception", null);
+ embeddedFile = spec.getEmbeddedFile();
+ ok = true;
}
+ //now test for actual attachment
+ spec = embeddedFiles.getNames().get("My first attachment");
+ assertNotNull("one attachment actually exists", spec);
+ assertEquals("existing file length", 17660,
spec.getEmbeddedFile().getLength());
+ spec = embeddedFiles.getNames().get("non-existent-file.docx");
+ assertNotNull(spec);
+ assertNull(spec.getFile());
+ assertNull(spec.getEmbeddedFile());
+ doc.close();
assertTrue("Was able to get file without exception", ok);
assertNull("EmbeddedFile was correctly null", embeddedFile);
}
Modified:
pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/font/TestFontEmbedding.java
==============================================================================
---
pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/font/TestFontEmbedding.java
Mon Jun 15 08:05:09 2026 (r1935333)
+++
pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/font/TestFontEmbedding.java
Mon Jun 15 08:27:52 2026 (r1935334)
@@ -575,7 +575,7 @@ public class TestFontEmbedding extends T
if (!testPDFToImage.doTestFile(pdf, IN_DIR.getAbsolutePath(),
OUT_DIR.getAbsolutePath()))
{
// don't fail, rendering is different on different systems, result
must be viewed manually
- System.err.println("Rendering of " + pdf + " failed or is not
identical to expected rendering in " + IN_DIR + " directory");
+ fail("Rendering of " + pdf + " failed or is not identical to
expected rendering in " + IN_DIR + " directory");
}
}
@@ -671,7 +671,7 @@ public class TestFontEmbedding extends T
if (!testPDFToImage.doTestFile(pdf, IN_DIR.getAbsolutePath(),
OUT_DIR.getAbsolutePath()))
{
// don't fail, rendering is different on different systems, result
must be viewed manually
- System.err.println("Rendering of " + pdf + " failed or is not
identical to expected rendering in " + IN_DIR + " directory");
+ fail("Rendering of " + pdf + " failed or is not identical to
expected rendering in " + IN_DIR + " directory");
}
}