stanfordnlp/CoreNLP · error · NullPointerException
Attempt to open file with null name
Error message
Attempt to open file with null name
What it means
IOUtils.getInputStreamFromURLOrClasspathOrFileSystem() resolves a resource by URL, classpath, or filesystem path. It throws NullPointerException immediately if the given name is null, since nothing can be resolved.
Solutions
- Validate the input is non-null before calling; fail with a clear message naming the missing config/flag.
- Provide the required value via -D property, environment variable, or option.
- Use Objects.requireNonNull(value, "which key") at the configuration boundary to catch it early.
- If the value is genuinely optional, guard the call: if (name != null) ...
Example fix
// before
InputStream in = IOUtils.getInputStreamFromURLOrClasspathOrFileSystem(props.getProperty("model"));
// after
String modelPath = props.getProperty("model");
Objects.requireNonNull(modelPath, "Missing required property: model");
InputStream in = IOUtils.getInputStreamFromURLOrClasspathOrFileSystem(modelPath); Defensive patterns
Strategy: validation
Validate before calling
if (name == null || name.trim().isEmpty()) {
throw new IllegalArgumentException("Resource name must be provided");
} Type guard
boolean isValidName(String s) {
return s != null && !s.trim().isEmpty();
} Try / catch
try {
InputStream in = IOUtils.getInputStreamFromURLOrClasspathOrFileSystem(name);
} catch (NullPointerException e) {
log.severe("Null resource name; check config key 'model' and CLI options");
} Prevention
- Use Objects.requireNonNull with a key name at config load time
- Check required options/env vars before calling IOUtils
- Return defaults for optional properties
When it happens
Trigger: Passing a null String to getInputStreamFromURLOrClasspathOrFileSystem (or its wrappers getDataInputStream, readObjectFromURLOrClasspathOrFileSystem, readerFromString), typically because a config property, argument, or System.getProperty lookup returned null.
Common situations: Missing command-line option or properties key; env var not set and read via System.getenv returning null; optional config field not provided; API default changed between library versions.
Related errors
- Cannot read from null object!
- Invalid buffer size : must be larger than 0
- argsToProperties could not read properties file: " + file
- attempt to get word when sentence and lattice are null!
- Attempt to make ObjectBank with empty file list
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/abd3226a24517306.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/io/IOUtils.java:485
InputStream is = findStreamInClassLoader(name);
return is != null || new File(name).exists();
}
/**
* Locates this file either using the given URL, or in the CLASSPATH, or in the file system
* The CLASSPATH takes priority over the file system!
* This stream is buffered and gunzipped (if necessary).
*
* @param textFileOrUrl The String specifying the URL/resource/file to load
* @return An InputStream for loading a resource
* @throws IOException On any IO error
* @throws NullPointerException Input parameter is null
*/
public static InputStream getInputStreamFromURLOrClasspathOrFileSystem(String textFileOrUrl)
throws IOException, NullPointerException {
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);
}View on GitHub (pinned to 1b7edd19c4)