Skip to content

Commit ccf5e00

Browse files
committed
Fix URI.from() architecture rule
1 parent e67e877 commit ccf5e00

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

jablib/src/test/java/org/jabref/model/entry/identifier/RFCTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.jabref.model.entry.identifier;
22

33
import java.net.URI;
4+
import java.net.URISyntaxException;
45
import java.util.Optional;
56

67
import org.junit.jupiter.api.Test;
@@ -30,8 +31,8 @@ void invalidRfc() {
3031
}
3132

3233
@Test
33-
void getExternalUri() {
34+
void getExternalUri() throws URISyntaxException {
3435
RFC rfc = new RFC("rfc7276");
35-
assertEquals(Optional.of(URI.create("https://www.rfc-editor.org/rfc/rfc7276")), rfc.getExternalURI());
36+
assertEquals(Optional.of(new URI("https://www.rfc-editor.org/rfc/rfc7276")), rfc.getExternalURI());
3637
}
3738
}

jabls/src/main/java/org/jabref/languageserver/util/LspParserHandler.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.io.IOException;
44
import java.io.Reader;
55
import java.net.URI;
6+
import java.net.URISyntaxException;
67
import java.nio.file.Path;
78
import java.util.List;
89
import java.util.Map;
@@ -28,7 +29,12 @@ public ParserResult parserResultFromString(String fileUri, String content, Impor
2829
// Otherwise, we could use `OpenDatabase.loadDatabase(path, importFormatPreferences, new DummyFileUpdateMonitor())`
2930
BibtexParser parser = new BibtexParser(importFormatPreferences);
3031
ParserResult parserResult = parser.parse(Reader.of(content));
31-
URI uri = URI.create(fileUri);
32+
URI uri;
33+
try {
34+
uri = new URI(fileUri);
35+
} catch (URISyntaxException e) {
36+
return ParserResult.fromError(e);
37+
}
3238
Path path = Path.of(uri);
3339
parserResult.getDatabaseContext().setDatabasePath(path);
3440
parserResults.put(fileUri, parserResult);

jabsrv-cli/src/main/java/org/jabref/http/server/cli/ServerCli.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.jabref.http.server.cli;
22

33
import java.net.URI;
4+
import java.net.URISyntaxException;
45
import java.nio.file.Files;
56
import java.nio.file.Path;
67
import java.util.ArrayList;
@@ -67,7 +68,13 @@ public Void call() throws InterruptedException {
6768
LOGGER.debug("Libraries to serve: {}", filesToServe);
6869

6970
String url = "http://" + host + ":" + port + "/";
70-
URI uri = URI.create(url);
71+
URI uri;
72+
try {
73+
uri = new URI(url);
74+
} catch (URISyntaxException e) {
75+
LOGGER.error("Invalid URL: {}", url);
76+
return null;
77+
}
7178

7279
Server server = new Server();
7380
HttpServer httpServer = server.run(filesToServe, uri);

0 commit comments

Comments
 (0)