{"record":{"id":"621b3fcdb70a8ca0","repo":"languagetool-org/languagetool","slug":"could-not-load-file-from-classpath-path","errorCode":null,"errorMessage":"Could not load file from classpath: '${path}'","messagePattern":"Could not load file from classpath: '(.+?)'","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"languagetool-core/src/main/java/org/languagetool/tools/Tools.java","lineNumber":269,"sourceCode":"  public static String getFullStackTrace(Throwable e) {\n    StringWriter sw = new StringWriter();\n    PrintWriter pw = new PrintWriter(sw);\n    e.printStackTrace(pw);\n    return sw.toString();\n  }\n\n  /**\n   * Load a file from the classpath using {@link Class#getResourceAsStream(String)}.\n   * Please load files in the {@code rules} and {@code resource} directories with\n   * {@link org.languagetool.broker.ResourceDataBroker} instead.\n   */\n  public static InputStream getStream(String path) throws IOException {\n    // the other ways to load the stream like\n    // \"Tools.class.getClass().getResourceAsStream(filename)\"\n    // don't work in a web context (using Grails):\n    InputStream is = JLanguageTool.getDataBroker().getAsStream(path);\n    if (is == null) {\n      throw new IOException(\"Could not load file from classpath: '\" + path + \"'\");\n    }\n    return is;\n  }\n\n  public static InputStream getStream(String path, String requiredHash) throws IOException, NoSuchAlgorithmException {\n    byte[] data;\n\n    try (InputStream is = getStream(path)) {\n      data = is.readAllBytes();\n    }\n\n    MessageDigest md = MessageDigest.getInstance(\"SHA-256\");\n    String computedHash = HexFormat.of().formatHex(md.digest(data));\n\n    if (!computedHash.equals(requiredHash)) {\n      throw new IOException(\"Checksum mismatch for the file '\" + path + \"': expected \" + requiredHash + \", got \" + computedHash);\n    }\n    return new ByteArrayInputStream(data);","sourceCodeStart":251,"sourceCodeEnd":287,"githubUrl":"https://github.com/languagetool-org/languagetool/blob/2e990059ce67d5e2a0f7f7ca5d31160c6709df4b/languagetool-core/src/main/java/org/languagetool/tools/Tools.java#L251-L287","documentation":"Tools.getStream failed to open the given path as a classpath resource via Class#getResourceAsStream; the resource is missing from the classpath or the path is malformed. Rules/resource files should instead go through ResourceDataBroker.","triggerScenarios":"Thrown at languagetool-core/src/main/java/org/languagetool/tools/Tools.java:269 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check the path spelling and that the file is on the classpath","Prefer ResourceDataBroker for files under rules/ or resource/","Ensure the resource is packaged in the running jar/module"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"2e990059ce67d5e2a0f7f7ca5d31160c6709df4b","analyzedAt":"2026-09-06T09:20:17.015Z","contentChangedAt":"2026-09-06T09:20:17.015Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}