SonarSource/sonarqube · critical · IllegalStateException
Fail to compute hash
Error message
Fail to compute hash
What it means
BatchIndex.start() builds an index of all JARs in the batch directory by appending an MD5 hash of each file; if reading a jar raises an IOException, it wraps it in this IllegalStateException. The batch directory must be readable and every *.jar inside hashable at startup.
Solutions
- Check file permissions/ownership of the jars in the batch directory and fix read access
- Re-copy or re-deploy the lib/batch directory from a clean distribution
- Look for truncated/zero-byte jars (interrupted upgrade) and replace them
- Exclude the SonarQube install directory from antivirus/backup locking and restart
Example fix
// before -rw------- batch.jar (unreadable by sonar user) // after chown sonar:sonar batch.jar && chmod 644 batch.jar
Defensive patterns
Strategy: validation
Validate before calling
// Pre-start check that every jar in the batch dir is readable:
for (File f : new File(batchDir).listFiles((d, n) -> n.endsWith(".jar"))) {
if (!f.canRead() || f.length() == 0) {
throw new IllegalStateException("Unreadable/empty jar in batch dir: " + f + " — fix permissions or redeploy");
}
} Try / catch
try {
batchIndex.start();
} catch (IllegalStateException e) {
if ("Fail to compute hash".equals(e.getMessage())) {
log.error("A batch jar is unreadable — check permissions, locks, or truncated files in " + batchDir, e);
// block startup or repair the directory before retrying
} else { throw e; }
} Prevention
- Run SonarQube under a user with read access to the entire install directory
- Never modify jars in lib/batch manually; redeploy from the distribution instead
- Exclude the install dir from antivirus/backup file locks
- Verify jar sizes/checksums after upgrades to catch truncation
When it happens
Trigger: Server startup / first batch WS call (get_index, get_file, ...) when a .jar in <sonarHome>/lib/batch (or configured batch dir) cannot be opened or read — e.g. permissions, file locked, or file truncated.
Common situations: Batch directory on a read-only or failing mount; partially copied/updated jars (upgrade interrupted); antivirus or backup tools locking files on Windows; wrong file permissions after manual copy.
Understand the failure class
Background: "failed to read file", EACCES, ENOENT and "could not read <path>" errors: when a program can't read a file from disk — this error's family across 49 libraries.
Related errors
- Bad filename
- Can not read file
- Can't read svg template
- Could not read properties from file:
- Error returned by Bitbucket Cloud
AI-assisted analysis of SonarSource/sonarqube@184c821202 (2026-09-09).
Data as JSON: /api/errors/93b5cc3fcf0133c4.
Report an issue: GitHub.
Appendix: source
Thrown at server/sonar-webserver-webapi/src/main/java/org/sonar/server/batch/BatchIndex.java:67
private File batchDir;
public BatchIndex(ServerFileSystem fs) {
this.fs = fs;
}
@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;
}
View on GitHub (pinned to 184c821202)