SonarSource/sonarqube · critical · IllegalStateException

folder not found

Error message

%s folder not found

What it means

BatchIndex.start() requires the batch directory (holding the JARs served to scanners) to exist; if it does not, it throws this IllegalStateException with the absolute path. This prevents the batch web services from serving scanner files from a nonexistent location.

Solutions

  1. Verify the batch directory exists at the path in the message; restore it from a full distribution
  2. If sonar.path.* properties override it, correct the configured path and restart
  3. Reinstall/repair the SonarQube server — the batch folder ships with the distribution
  4. If running in a container, use the official image or fix the Dockerfile to include lib/batch

Example fix

// before (missing dir)
/opt/sonarqube/lib/  (no batch/ folder)
// after
cp -r sonarqube-9.9/lib/batch /opt/sonarqube/lib/
Defensive patterns

Strategy: validation

Validate before calling

// Verify the batch directory exists before starting the server:
File batchDir = new File(sonarHome, "lib/batch");
if (!batchDir.isDirectory()) {
  throw new IllegalStateException("Batch folder missing at " + batchDir + " — reinstall from a full distribution");
}

Try / catch

try {
  batchIndex.start();
} catch (IllegalStateException e) {
  if (e.getMessage() != null && e.getMessage().endsWith("folder not found")) {
    log.error("Batch directory missing — restore lib/batch from the official distribution", e);
  } else { throw e; }
}

Prevention

When it happens

Trigger: Starting the Compute/Web server or invoking batch endpoints when the configured batch directory (e.g. sonar.path.home/lib/batch or an overridden path) is absent — typically a broken or incomplete installation or a bad path override.

Common situations: Manual install where lib/batch was never copied; deleted batch dir during cleanup; overridden sonar.path properties pointing at a wrong location; container images built without the batch libs.

Related errors


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

Appendix: source

Thrown at server/sonar-webserver-webapi/src/main/java/org/sonar/server/batch/BatchIndex.java:72

  @Override
  public void start() {
    StringBuilder sb = new StringBuilder();
    batchDir = new File(fs.getHomeDir(), "lib/scanner");
    if (batchDir.exists()) {
      Collection<File> files = FileUtils.listFiles(batchDir, HiddenFileFilter.VISIBLE, FileFilterUtils.directoryFileFilter());
      for (File file : files) {
        String filename = file.getName();
        if (StringUtils.endsWith(filename, ".jar")) {
          try (FileInputStream fis = new FileInputStream(file)) {
            sb.append(filename).append('|').append(DigestUtils.md5Hex(fis)).append(CharUtils.LF);
          } catch (IOException e) {
            throw new IllegalStateException("Fail to compute hash", e);
          }
        }
      }
    } else {
      throw new IllegalStateException(format("%s folder not found", batchDir.getAbsolutePath()));
    }
    this.index = sb.toString();
  }

  @Override
  public void stop() {
    // Nothing to do
  }

  String getIndex() {
    return index;
  }

  File getFile(String filename) {
    try {
      File input = new File(batchDir, filename);
      if (!FilenameUtils.directoryContains(batchDir.getCanonicalPath(), input.getCanonicalPath()) || !input.exists()) {
        throw new NotFoundException("Bad filename: " + filename);

View on GitHub (pinned to 184c821202)