SonarSource/sonarqube · error · IllegalStateException

Cannot load %s from classpath

Error message

Cannot load %s from classpath

What it means

SonarQubeVersionHelper reads the embedded sonar-api-version (SONARQUBE_VERSION_PATH) resource from the classpath to determine the running SonarQube version. If the resource stream cannot be read and an IOException occurs, it wraps it in an IllegalStateException 'Cannot load <path> from classpath'. It indicates the packaged version file is missing or unreadable.

Source

Thrown at server/sonar-main/src/main/java/org/sonar/application/config/SonarQubeVersionHelper.java:55

  public static String getSonarqubeVersion() {
    if (sonarqubeVersion == null) {
      loadVersion();
    }
    return sonarqubeVersion;
  }

  private static synchronized void loadVersion() {
    try {
      try (BufferedReader in = new BufferedReader(
        new InputStreamReader(
          SonarQubeVersionHelper.class.getResourceAsStream(SONARQUBE_VERSION_PATH),
          StandardCharsets.UTF_8
        ))) {
        sonarqubeVersion = in.readLine();
      }
    } catch (IOException e) {
      throw new IllegalStateException(format("Cannot load %s from classpath", SONARQUBE_VERSION_PATH), e);
    }
  }
}

View on GitHub (pinned to 184c821202)

Solutions

  1. Re-download/reinstall the unmodified SonarQube distribution
  2. Verify the version resource file exists inside the JAR (e.g. unzip -l sonar-application.jar | grep version)
  3. Check assembly/shade resource includes if building SonarQube from source
  4. Inspect the wrapped IOException cause for the underlying filesystem problem

Example fix

// pom.xml resource filtering excluding files
<resources><resource><directory>src/main/resources</directory><excludes><exclude>**/sonar-api-version.txt</exclude></excludes></resource></resources>
// after: remove the exclude so the version file ships in the JAR
Defensive patterns

Strategy: try-catch

Validate before calling

try (InputStream in = SonarQubeVersionHelper.class.getResourceAsStream("/sonar-api-version.txt")) {
  if (in == null) throw new IllegalStateException("Version resource missing from distribution JAR");
}

Try / catch

try { Version v = SonarQubeVersionHelper.getSonarqubeVersion(); } catch (IllegalStateException e) { log.error("Version resource unreadable; reinstall distribution", e); throw e; }

Prevention

When it happens

Trigger: IOException while reading SONARQUBE_VERSION_PATH from the classpath — e.g. the resource stream was null/unreadable, a broken JAR packaging stripped the resource, or an IO error opening the stream inside the try-with-resources.

Common situations: Custom or trimmed distributions that excluded the version resource file; corrupted installation JARs; shading/assembly plugins that fail to copy resources into the artifact; running from a partially extracted distribution.

Related errors


AI-assisted analysis of SonarSource/sonarqube@184c821202 (2026-09-09). Data as JSON: /api/errors/802c321548b65834. Report an issue: GitHub.