Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix exception for unlinked files #6567

Merged
merged 5 commits into from
Jun 2, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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