stanfordnlp/CoreNLP · error · IOException
Unable to open " " as class path, filename or URL
Error message
Unable to open "${textFileOrUrl}" as class path, filename or URL What it means
After trying classpath, filesystem, and URL resolution, getInputStreamFromURLOrClasspathOrFileSystem gives up and throws IOException 'Unable to open "<name>" as class path, filename or URL'. All three resolution strategies failed, so the resource is unreachable by any supported means.
Solutions
- Check the file exists at the literal path (ls) or add its directory/jar to the classpath (-cp).
- If it's a classpath resource, verify it's inside the JAR (jar tf app.jar | grep name) and the path has no leading slash mistakes.
- If it's a URL, verify the scheme/host with curl and correct typos.
- Ensure model/resource files are downloaded or added as a Maven/Gradle dependency before running.
Example fix
// before
props.load(IOUtils.readerFromString("StanfordCoreNLP-chinese.properties")); // not on classpath
// after
File p = new File("conf/StanfordCoreNLP-chinese.properties");
if (!p.exists()) throw new FileNotFoundException(p.getAbsolutePath());
props.load(IOUtils.readerFromString(p.getAbsolutePath())); Defensive patterns
Strategy: try-catch
Validate before calling
File f = new File(name);
if (!f.exists() && IOUtils.class.getResourceAsStream(name.startsWith("/") ? name : "/" + name) == null) {
throw new FileNotFoundException(name + " is neither a file nor a classpath resource");
} Try / catch
try {
InputStream in = IOUtils.getInputStreamFromURLOrClasspathOrFileSystem(name);
} catch (IOException e) {
if (e.getMessage().startsWith("Unable to open")) {
log.severe("Resource not found as classpath/file/URL: " + name);
}
} Prevention
- Package resources in the JAR and verify with jar tf
- Add model jars to the classpath
- Validate URLs with curl before use
- Run from the intended working directory
When it happens
Trigger: The string is not a valid URL, is not on the classpath, and is not an existing file: wrong filename, resource not packaged in the JAR, typo'd URL scheme, or file deleted/not downloaded.
Common situations: Missing model files (e.g. CoreNLP models jar not on classpath); running from a different working directory than expected; resource present in sources but not copied into the built artifact; HTTPS URL with scheme typo (htp://).
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
- Error leading weights from
- ERROR: Could not find properties file in the classpath!
- ERROR: cannot find properties file
- ioe
- Error loading classifier from
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/cec309672dc9eff2.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/io/IOUtils.java:501
InputStream in;
if (textFileOrUrl == null) {
throw new NullPointerException("Attempt to open file with null name");
} else if (textFileOrUrl.matches("https?://.*")) {
URL u = new URL(textFileOrUrl);
URLConnection uc = u.openConnection();
in = uc.getInputStream();
} else {
try {
in = findStreamInClasspathOrFileSystem(textFileOrUrl);
} catch (FileNotFoundException e) {
try {
// Maybe this happens to be some other format of URL?
URL u = new URL(textFileOrUrl);
URLConnection uc = u.openConnection();
in = uc.getInputStream();
} catch (IOException e2) {
// Don't make the original exception a cause, since it is usually bogus
throw new IOException("Unable to open \"" +
textFileOrUrl + "\" as " + "class path, filename or URL"); // , e2);
}
}
}
// If it is a GZIP stream then ungzip it
if (textFileOrUrl.endsWith(".gz")) {
try {
in = new GZIPInputStream(in);
} catch (Exception e) {
throw new RuntimeIOException("Resource or file looks like a gzip file, but is not: " + textFileOrUrl, e);
}
}
// buffer this stream. even gzip streams benefit from buffering,
// such as for the shift reduce parser [cdm 2016: I think this is only because default buffer is small; see below]
in = new BufferedInputStream(in);
View on GitHub (pinned to 1b7edd19c4)