Skip to content

Commit

Permalink
Merge pull request #6567 from ZhouSky/fix-for-issue-5815
Browse files Browse the repository at this point in the history
Fix exception for unlinked files
  • Loading branch information
Siedlerchr authored Jun 2, 2020
2 parents ea3acb7 + a78ffa5 commit 9f673f6
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -376,11 +376,15 @@ private List<Path> getFileListFromNode(CheckBoxTreeItem<FileNodeWrapper> node) {
List<Path> filesList = new ArrayList<>();
for (TreeItem<FileNodeWrapper> childNode : node.getChildren()) {
CheckBoxTreeItem<FileNodeWrapper> child = (CheckBoxTreeItem<FileNodeWrapper>) 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;
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/org/jabref/logic/xmp/XmpUtilReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public static List<BibEntry> readXmp(Path path, XmpPreferences xmpPreferences)
* <p/>
*
*
* @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<XMPMetadata> getXmpMetadata(PDDocument document) throws IOException {
PDDocumentCatalog catalog = document.getDocumentCatalog();
Expand All @@ -120,6 +120,10 @@ private static List<XMPMetadata> 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
Expand Down
9 changes: 9 additions & 0 deletions src/test/java/org/jabref/logic/xmp/XmpUtilReaderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<BibEntry> entries = XmpUtilReader.readXmp(Path.of(XmpUtilShared.class.getResource("no_description_metadata.pdf").toURI()), xmpPreferences);
assertEquals(Collections.emptyList(), entries);
}
}
Binary file not shown.

0 comments on commit 9f673f6

Please sign in to comment.