You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opennlp.apache.org by ma...@apache.org on 2026/03/15 18:46:45 UTC
(opennlp) 02/03: OPENNLP-1735: Fix Windows classpath model discovery after JDK 21 migration
This is an automated email from the ASF dual-hosted git repository.
mawiesne pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/opennlp.git
commit 09305ab6284df51ff0f435f8e0df61c603e63f63
Author: Richard Zowalla <rz...@apache.org>
AuthorDate: Sun Mar 15 19:27:09 2026 +0100
OPENNLP-1735: Fix Windows classpath model discovery after JDK 21 migration
The URI constructor does not handle Windows-style paths (e.g., C:\path\to\file.jar) correctly, causing silent failures in getClassPathUrlsFromSystemProperty().
Uses Path.of().toUri().toURL() which properly converts platform-specific paths.
---
.../opennlp/tools/models/simple/SimpleClassPathModelFinder.java | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/opennlp-core/opennlp-models/src/main/java/opennlp/tools/models/simple/SimpleClassPathModelFinder.java b/opennlp-core/opennlp-models/src/main/java/opennlp/tools/models/simple/SimpleClassPathModelFinder.java
index 0a85fb98..44bf4d61 100644
--- a/opennlp-core/opennlp-models/src/main/java/opennlp/tools/models/simple/SimpleClassPathModelFinder.java
+++ b/opennlp-core/opennlp-models/src/main/java/opennlp/tools/models/simple/SimpleClassPathModelFinder.java
@@ -25,6 +25,7 @@ import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLClassLoader;
+import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@@ -68,7 +69,6 @@ import opennlp.tools.models.ClassPathModelFinder;
public class SimpleClassPathModelFinder extends AbstractClassPathModelFinder implements ClassPathModelFinder {
private static final Logger logger = LoggerFactory.getLogger(SimpleClassPathModelFinder.class);
- private static final String FILE_PREFIX = "file";
private static final Pattern CLASSPATH_SEPARATOR_PATTERN_WINDOWS = Pattern.compile(";");
private static final Pattern CLASSPATH_SEPARATOR_PATTERN_UNIX = Pattern.compile(":");
// ; for Windows, : for Linux/OSX
@@ -219,8 +219,8 @@ public class SimpleClassPathModelFinder extends AbstractClassPathModelFinder imp
final List<URL> jarUrls = new ArrayList<>();
for (String classPath: matches) {
try {
- jarUrls.add(new URI(FILE_PREFIX, "", classPath, null).toURL());
- } catch (MalformedURLException | URISyntaxException ignored) {
+ jarUrls.add(Path.of(classPath).toUri().toURL());
+ } catch (MalformedURLException ignored) {
//if we cannot parse a URL from the system property, just ignore it...
//we couldn't load it anyway
}