{"record":{"id":"82af440050b92ab2","repo":"apache/druid","slug":"resource-not-found-s","errorCode":null,"errorMessage":"Resource not found: [%s]","messagePattern":"Resource not found: \\[(.+?)\\]","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"processing/src/main/java/org/apache/druid/java/util/common/StringUtils.java","lineNumber":772,"sourceCode":"   * Shorten \"s\" to \"maxBytes\" chars. Fast and loose because these are *chars* not *bytes*. Use\n   * {@link #chop(String, int)} for slower, but accurate chopping.\n   */\n  @Nullable\n  public static String fastLooseChop(@Nullable final String s, final int maxBytes)\n  {\n    if (s == null || s.length() <= maxBytes) {\n      return s;\n    } else {\n      return s.substring(0, maxBytes);\n    }\n  }\n\n  public static String getResource(Object ref, String resource)\n  {\n    try {\n      InputStream is = ref.getClass().getResourceAsStream(resource);\n      if (is == null) {\n        throw new ISE(\"Resource not found: [%s]\", resource);\n      }\n      return IOUtils.toString(is, StandardCharsets.UTF_8);\n    }\n    catch (IOException e) {\n      throw new ISE(e, \"Cannot load resource: [%s]\", resource);\n    }\n  }\n\n  /**\n   This method is removed from commons lang3.\n   https://commons.apache.org/proper/commons-lang/article3_0.html\n   */\n  public static String escapeSql(String str)\n  {\n    return str == null ? null : StringUtils.replace(str, \"'\", \"''\");\n  }\n\n  /**","sourceCodeStart":754,"sourceCodeEnd":790,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/java/util/common/StringUtils.java#L754-L790","documentation":"StringUtils.getResource(Object ref, String resource) loads a classpath resource relative to ref's class and returns it as a UTF-8 string. If getResourceAsStream returns null — the resource does not exist on the classpath — it throws IllegalStateException \"Resource not found: [%s]\".","triggerScenarios":"Calling StringUtils.getResource(SomeClass.class, \"/path/file.txt\") where the file is missing from the jar/classpath, the path is misspelled, or the leading slash is wrong (absolute vs package-relative lookup).","commonSituations":"Native-query/worker scripts or config templates not packaged in the jar; resources lost after a build/packaging change; wrong case-sensitive path on Linux.","solutions":["Verify the resource path exists on the classpath exactly as given (case-sensitive, correct leading slash: \"/foo.txt\" vs \"foo.txt\").","Check the jar contents (jar tf app.jar | grep resource) to confirm packaging includes the file.","Ensure the resource is included by the build (Maven resources filtering/excludes).","Catch IllegalStateException and provide a fallback default resource or clearer error."],"exampleFix":"// before\nString sql = StringUtils.getResource(Main.class, \"/queires/init.sql\");\n// after\nString sql = StringUtils.getResource(Main.class, \"/queries/init.sql\"); // fixed typo; ensure file is in src/main/resources","handlingStrategy":"validation","validationCode":"java.net.URL url = Main.class.getResource(path);\nif (url == null) { throw new IllegalArgumentException(\"Resource missing from classpath: \" + path); }","typeGuard":"boolean resourceExists(Class<?> c, String path) { return c.getResource(path) != null; }","tryCatchPattern":"try { return StringUtils.getResource(ref, resource); } catch (IllegalStateException e) { throw new RuntimeException(\"Check packaging/classpath for \" + resource, e); }","preventionTips":["Verify resources are under src/main/resources and included by the build","Use a leading slash for absolute classpath paths; mind case sensitivity on Linux","List jar contents (jar tf) to confirm the resource shipped"],"tags":["classpath","resource-loading","file-not-found"],"backgroundTag":"resource-not-found","analyzedSha":"9b90983fd291f26935af934383ce360473179e4d","analyzedAt":"2026-09-07T13:32:30.957Z","contentChangedAt":"2026-09-07T13:32:30.957Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}