diff --git a/src/main/java/org/jabref/gui/externalfiles/FindUnlinkedFilesDialog.java b/src/main/java/org/jabref/gui/externalfiles/FindUnlinkedFilesDialog.java index 1b455afdbdd..ceaea36f3d2 100644 --- a/src/main/java/org/jabref/gui/externalfiles/FindUnlinkedFilesDialog.java +++ b/src/main/java/org/jabref/gui/externalfiles/FindUnlinkedFilesDialog.java @@ -376,11 +376,15 @@ private List getFileListFromNode(CheckBoxTreeItem node) { List filesList = new ArrayList<>(); for (TreeItem childNode : node.getChildren()) { CheckBoxTreeItem child = (CheckBoxTreeItem) childNode; - if (child.isLeaf() && child.isSelected()) { - Path nodeFile = child.getValue().path; - if ((nodeFile != null) && Files.isRegularFile(nodeFile)) { - filesList.add(nodeFile); + if (child.isLeaf()) { + if (child.isSelected()) { + Path nodeFile = child.getValue().path; + if ((nodeFile != null) && Files.isRegularFile(nodeFile)) { + filesList.add(nodeFile); + } } + } else { + filesList.addAll(getFileListFromNode(child)); } } return filesList; diff --git a/src/main/java/org/jabref/logic/xmp/XmpUtilReader.java b/src/main/java/org/jabref/logic/xmp/XmpUtilReader.java index b73df2c79bf..f58d5fda413 100644 --- a/src/main/java/org/jabref/logic/xmp/XmpUtilReader.java +++ b/src/main/java/org/jabref/logic/xmp/XmpUtilReader.java @@ -104,7 +104,7 @@ public static List readXmp(Path path, XmpPreferences xmpPreferences) *

* * - * @return empty Optional if no metadata has been found + * @return empty List if no metadata has been found, or cannot properly find start or end tag in metadata */ private static List getXmpMetadata(PDDocument document) throws IOException { PDDocumentCatalog catalog = document.getDocumentCatalog(); @@ -120,6 +120,10 @@ private static List getXmpMetadata(PDDocument document) throws IOEx int startDescriptionSection = xmp.indexOf(START_TAG); int endDescriptionSection = xmp.lastIndexOf(END_TAG) + END_TAG.length(); + if (startDescriptionSection < 0 || startDescriptionSection > endDescriptionSection || endDescriptionSection == END_TAG.length() - 1) { + return metaList; + } + // XML header for the xmpDomParser String start = xmp.substring(0, startDescriptionSection); // descriptionArray - mid part of the textual metadata diff --git a/src/test/java/org/jabref/logic/xmp/XmpUtilReaderTest.java b/src/test/java/org/jabref/logic/xmp/XmpUtilReaderTest.java index 37c43679ae1..c30f8702d2c 100644 --- a/src/test/java/org/jabref/logic/xmp/XmpUtilReaderTest.java +++ b/src/test/java/org/jabref/logic/xmp/XmpUtilReaderTest.java @@ -109,4 +109,13 @@ void testReadPDMetadata() throws IOException, URISyntaxException, ParseException assertEquals(entryFromBibFile.get(), entries.get(0)); } + + /** + * Tests an pdf file with metadata which has no description section. + */ + @Test + void testReadNoDescriptionMetadata() throws IOException, URISyntaxException { + List entries = XmpUtilReader.readXmp(Path.of(XmpUtilShared.class.getResource("no_description_metadata.pdf").toURI()), xmpPreferences); + assertEquals(Collections.emptyList(), entries); + } } diff --git a/src/test/resources/org/jabref/logic/xmp/no_description_metadata.pdf b/src/test/resources/org/jabref/logic/xmp/no_description_metadata.pdf new file mode 100644 index 00000000000..76fb27b903c Binary files /dev/null and b/src/test/resources/org/jabref/logic/xmp/no_description_metadata.pdf differ