{"record":{"id":"abd3226a24517306","repo":"stanfordnlp/CoreNLP","slug":"attempt-to-open-file-with-null-name","errorCode":null,"errorMessage":"Attempt to open file with null name","messagePattern":"Attempt to open file with null name","errorType":"exception","errorClass":"NullPointerException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/io/IOUtils.java","lineNumber":485,"sourceCode":"    InputStream is = findStreamInClassLoader(name);\n    return is != null || new File(name).exists();\n  }\n\n  /**\n   * Locates this file either using the given URL, or in the CLASSPATH, or in the file system\n   * The CLASSPATH takes priority over the file system!\n   * This stream is buffered and gunzipped (if necessary).\n   *\n   * @param textFileOrUrl The String specifying the URL/resource/file to load\n   * @return An InputStream for loading a resource\n   * @throws IOException On any IO error\n   * @throws NullPointerException Input parameter is null\n   */\n  public static InputStream getInputStreamFromURLOrClasspathOrFileSystem(String textFileOrUrl)\n          throws IOException, NullPointerException {\n    InputStream in;\n    if (textFileOrUrl == null) {\n      throw new NullPointerException(\"Attempt to open file with null name\");\n    } else if (textFileOrUrl.matches(\"https?://.*\")) {\n      URL u = new URL(textFileOrUrl);\n      URLConnection uc = u.openConnection();\n      in = uc.getInputStream();\n    } else {\n      try {\n        in = findStreamInClasspathOrFileSystem(textFileOrUrl);\n      } catch (FileNotFoundException e) {\n        try {\n          // Maybe this happens to be some other format of URL?\n          URL u = new URL(textFileOrUrl);\n          URLConnection uc = u.openConnection();\n          in = uc.getInputStream();\n        } catch (IOException e2) {\n          // Don't make the original exception a cause, since it is usually bogus\n          throw new IOException(\"Unable to open \\\"\" +\n                  textFileOrUrl + \"\\\" as \" + \"class path, filename or URL\"); // , e2);\n        }","sourceCodeStart":467,"sourceCodeEnd":503,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/io/IOUtils.java#L467-L503","documentation":"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.","triggerScenarios":"Passing a null String to getInputStreamFromURLOrClasspathOrFileSystem (or its wrappers getDataInputStream, readObjectFromURLOrClasspathOrFileSystem, readerFromString), typically because a config property, argument, or System.getProperty lookup returned null.","commonSituations":"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.","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) ..."],"exampleFix":"// before\nInputStream in = IOUtils.getInputStreamFromURLOrClasspathOrFileSystem(props.getProperty(\"model\"));\n// after\nString modelPath = props.getProperty(\"model\");\nObjects.requireNonNull(modelPath, \"Missing required property: model\");\nInputStream in = IOUtils.getInputStreamFromURLOrClasspathOrFileSystem(modelPath);","handlingStrategy":"validation","validationCode":"if (name == null || name.trim().isEmpty()) {\n  throw new IllegalArgumentException(\"Resource name must be provided\");\n}","typeGuard":"boolean isValidName(String s) {\n  return s != null && !s.trim().isEmpty();\n}","tryCatchPattern":"try {\n  InputStream in = IOUtils.getInputStreamFromURLOrClasspathOrFileSystem(name);\n} catch (NullPointerException e) {\n  log.severe(\"Null resource name; check config key 'model' and CLI options\");\n}","preventionTips":["Use Objects.requireNonNull with a key name at config load time","Check required options/env vars before calling IOUtils","Return defaults for optional properties"],"tags":["null","argument-validation","io"],"backgroundTag":"null-argument","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}