Skip to content

Commit

Permalink
Fix exception when editing URL file
Browse files Browse the repository at this point in the history
Fixes #8008
  • Loading branch information
Siedlerchr committed Aug 20, 2021
1 parent 631f27c commit efa248e
Showing 1 changed file with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.jabref.gui.linkedfile;

import java.net.MalformedURLException;
import java.net.URL;
import java.nio.file.Path;
import java.util.List;
import java.util.Optional;
Expand Down Expand Up @@ -125,7 +127,17 @@ public ObjectProperty<ExternalFileType> selectedExternalFileTypeProperty() {
}

public LinkedFile getNewLinkedFile() {
return new LinkedFile(description.getValue(), Path.of(link.getValue()), monadicSelectedExternalFileType.getValue().map(ExternalFileType::toString).orElse(""));
String fileType = monadicSelectedExternalFileType.getValue().map(ExternalFileType::toString).orElse("");

if (LinkedFile.isOnlineLink(link.getValue())) {
try {
return new LinkedFile(description.getValue(), new URL(link.getValue()), fileType);
} catch (MalformedURLException e) {
//ignore
return new LinkedFile(description.getValue(), link.getValue(), fileType);
}
}
return new LinkedFile(description.getValue(), Path.of(link.getValue()), fileType);
}

private String relativize(Path filePath) {
Expand Down

0 comments on commit efa248e

Please sign in to comment.