{"record":{"id":"cec309672dc9eff2","repo":"stanfordnlp/CoreNLP","slug":"unable-to-open-textfileorurl-as-class-path-f","errorCode":null,"errorMessage":"Unable to open \"${textFileOrUrl}\" as class path, filename or URL","messagePattern":"Unable to open \"(.+?)\" as class path, filename or URL","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/io/IOUtils.java","lineNumber":501,"sourceCode":"    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        }\n      }\n    }\n\n    // If it is a GZIP stream then ungzip it\n    if (textFileOrUrl.endsWith(\".gz\")) {\n      try {\n        in = new GZIPInputStream(in);\n      } catch (Exception e) {\n        throw new RuntimeIOException(\"Resource or file looks like a gzip file, but is not: \" + textFileOrUrl, e);\n      }\n    }\n\n    // buffer this stream.  even gzip streams benefit from buffering,\n    // such as for the shift reduce parser [cdm 2016: I think this is only because default buffer is small; see below]\n    in = new BufferedInputStream(in);\n","sourceCodeStart":483,"sourceCodeEnd":519,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/io/IOUtils.java#L483-L519","documentation":"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.","triggerScenarios":"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.","commonSituations":"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://).","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."],"exampleFix":"// before\nprops.load(IOUtils.readerFromString(\"StanfordCoreNLP-chinese.properties\")); // not on classpath\n// after\nFile p = new File(\"conf/StanfordCoreNLP-chinese.properties\");\nif (!p.exists()) throw new FileNotFoundException(p.getAbsolutePath());\nprops.load(IOUtils.readerFromString(p.getAbsolutePath()));","handlingStrategy":"try-catch","validationCode":"File f = new File(name);\nif (!f.exists() && IOUtils.class.getResourceAsStream(name.startsWith(\"/\") ? name : \"/\" + name) == null) {\n  throw new FileNotFoundException(name + \" is neither a file nor a classpath resource\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  InputStream in = IOUtils.getInputStreamFromURLOrClasspathOrFileSystem(name);\n} catch (IOException e) {\n  if (e.getMessage().startsWith(\"Unable to open\")) {\n    log.severe(\"Resource not found as classpath/file/URL: \" + name);\n  }\n}","preventionTips":["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"],"tags":["io","resource-not-found","classpath","url"],"backgroundTag":"resource-not-found","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}