Skip to content

Commit 923408c

Browse files
committed
Add log message for invalid Version in the catalog
DEVSIX-5094
1 parent 6bf4ecf commit 923408c

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

io/src/main/java/com/itextpdf/io/LogMessageConstant.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ public final class LogMessageConstant {
8989
public static final String DOCUMENT_HAS_CONFLICTING_OCG_NAMES = "Document has conflicting names for optional content groups. Groups with conflicting names will be renamed";
9090
public static final String DOCUMENT_IDS_ARE_CORRUPTED = "The document original and/or modified id is corrupted";
9191
public static final String DOCUMENT_SERIALIZATION_EXCEPTION_RAISED = "Unhandled exception while serialization";
92+
public static final String DOCUMENT_VERSION_IN_CATALOG_CORRUPTED = "The document version specified in catalog is corrupted";
9293
public static final String DURING_CONSTRUCTION_OF_ICC_PROFILE_ERROR_OCCURRED = "During the construction of the ICC profile, the {0} error with message \"{1}\" occurred, the ICC profile will not be installed in the image.";
9394
public static final String ELEMENT_DOES_NOT_FIT_AREA = "Element does not fit current area. {0}";
9495
public static final String ELEMENT_WAS_FORCE_PLACED_KEEP_WITH_NEXT_WILL_BE_IGNORED = "Element was placed in a forced way. Keep with next property will be ignored";

kernel/src/main/java/com/itextpdf/kernel/pdf/PdfDocument.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1946,7 +1946,9 @@ protected void open(PdfVersion newPdfVersion) {
19461946
if (catalogVersion.compareTo(pdfVersion) > 0) {
19471947
pdfVersion = catalogVersion;
19481948
}
1949-
} catch (IllegalArgumentException ignored){
1949+
} catch (IllegalArgumentException e) {
1950+
LoggerFactory.getLogger(PdfDocument.class)
1951+
.error(LogMessageConstant.DOCUMENT_VERSION_IN_CATALOG_CORRUPTED);
19501952
}
19511953
}
19521954
PdfStream xmpMetadataStream = catalog.getPdfObject().getAsStream(PdfName.Metadata);

kernel/src/test/java/com/itextpdf/kernel/pdf/PdfDocumentTest.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -525,10 +525,15 @@ public void removePageWithInvalidOutlineTest() throws IOException, InterruptedEx
525525
}
526526

527527
@Test
528+
@LogMessages(messages = {
529+
@LogMessage(messageTemplate = LogMessageConstant.DOCUMENT_VERSION_IN_CATALOG_CORRUPTED,
530+
logLevel = LogLevelConstants.ERROR)
531+
})
528532
public void openDocumentWithInvalidCatalogVersionTest() throws IOException {
529-
PdfReader reader = new PdfReader(SOURCE_FOLDER + "sample-with-invalid-catalog-version.pdf");
530-
PdfDocument pdfDocument = new PdfDocument(reader);
531-
Assert.assertNotNull(pdfDocument);
533+
try (PdfReader reader = new PdfReader(SOURCE_FOLDER + "sample-with-invalid-catalog-version.pdf");
534+
PdfDocument pdfDocument = new PdfDocument(reader)) {
535+
Assert.assertNotNull(pdfDocument);
536+
}
532537
}
533538

534539

0 commit comments

Comments
 (0)