apache/druid · error · IllegalStateException

Resource not found: [ ]

Error message

Resource not found: [%s]

What it means

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]".

Solutions

  1. Verify the resource path exists on the classpath exactly as given (case-sensitive, correct leading slash: "/foo.txt" vs "foo.txt").
  2. Check the jar contents (jar tf app.jar | grep resource) to confirm packaging includes the file.
  3. Ensure the resource is included by the build (Maven resources filtering/excludes).
  4. Catch IllegalStateException and provide a fallback default resource or clearer error.

Example fix

// before
String sql = StringUtils.getResource(Main.class, "/queires/init.sql");
// after
String sql = StringUtils.getResource(Main.class, "/queries/init.sql"); // fixed typo; ensure file is in src/main/resources
Defensive patterns

Strategy: validation

Validate before calling

java.net.URL url = Main.class.getResource(path);
if (url == null) { throw new IllegalArgumentException("Resource missing from classpath: " + path); }

Type guard

boolean resourceExists(Class<?> c, String path) { return c.getResource(path) != null; }

Try / catch

try { return StringUtils.getResource(ref, resource); } catch (IllegalStateException e) { throw new RuntimeException("Check packaging/classpath for " + resource, e); }

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of apache/druid@9b90983fd2 (2026-09-07). Data as JSON: /api/errors/82af440050b92ab2. Report an issue: GitHub.

Appendix: source

Thrown at processing/src/main/java/org/apache/druid/java/util/common/StringUtils.java:772

   * Shorten "s" to "maxBytes" chars. Fast and loose because these are *chars* not *bytes*. Use
   * {@link #chop(String, int)} for slower, but accurate chopping.
   */
  @Nullable
  public static String fastLooseChop(@Nullable final String s, final int maxBytes)
  {
    if (s == null || s.length() <= maxBytes) {
      return s;
    } else {
      return s.substring(0, maxBytes);
    }
  }

  public static String getResource(Object ref, String resource)
  {
    try {
      InputStream is = ref.getClass().getResourceAsStream(resource);
      if (is == null) {
        throw new ISE("Resource not found: [%s]", resource);
      }
      return IOUtils.toString(is, StandardCharsets.UTF_8);
    }
    catch (IOException e) {
      throw new ISE(e, "Cannot load resource: [%s]", resource);
    }
  }

  /**
   This method is removed from commons lang3.
   https://commons.apache.org/proper/commons-lang/article3_0.html
   */
  public static String escapeSql(String str)
  {
    return str == null ? null : StringUtils.replace(str, "'", "''");
  }

  /**

View on GitHub (pinned to 9b90983fd2)