{"record":{"id":"93b5cc3fcf0133c4","repo":"SonarSource/sonarqube","slug":"fail-to-compute-hash","errorCode":null,"errorMessage":"Fail to compute hash","messagePattern":"Fail to compute hash","errorType":"exception","errorClass":"IllegalStateException","httpStatus":500,"severity":"critical","filePath":"server/sonar-webserver-webapi/src/main/java/org/sonar/server/batch/BatchIndex.java","lineNumber":67,"sourceCode":"  private File batchDir;\n\n  public BatchIndex(ServerFileSystem fs) {\n    this.fs = fs;\n  }\n\n  @Override\n  public void start() {\n    StringBuilder sb = new StringBuilder();\n    batchDir = new File(fs.getHomeDir(), \"lib/scanner\");\n    if (batchDir.exists()) {\n      Collection<File> files = FileUtils.listFiles(batchDir, HiddenFileFilter.VISIBLE, FileFilterUtils.directoryFileFilter());\n      for (File file : files) {\n        String filename = file.getName();\n        if (StringUtils.endsWith(filename, \".jar\")) {\n          try (FileInputStream fis = new FileInputStream(file)) {\n            sb.append(filename).append('|').append(DigestUtils.md5Hex(fis)).append(CharUtils.LF);\n          } catch (IOException e) {\n            throw new IllegalStateException(\"Fail to compute hash\", e);\n          }\n        }\n      }\n    } else {\n      throw new IllegalStateException(format(\"%s folder not found\", batchDir.getAbsolutePath()));\n    }\n    this.index = sb.toString();\n  }\n\n  @Override\n  public void stop() {\n    // Nothing to do\n  }\n\n  String getIndex() {\n    return index;\n  }\n","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/SonarSource/sonarqube/blob/184c821202192afc1c599fc912d0889b69fffa53/server/sonar-webserver-webapi/src/main/java/org/sonar/server/batch/BatchIndex.java#L49-L85","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\n-rw------- batch.jar   (unreadable by sonar user)\n// after\nchown sonar:sonar batch.jar && chmod 644 batch.jar","handlingStrategy":"validation","validationCode":"// Pre-start check that every jar in the batch dir is readable:\nfor (File f : new File(batchDir).listFiles((d, n) -> n.endsWith(\".jar\"))) {\n  if (!f.canRead() || f.length() == 0) {\n    throw new IllegalStateException(\"Unreadable/empty jar in batch dir: \" + f + \" — fix permissions or redeploy\");\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  batchIndex.start();\n} catch (IllegalStateException e) {\n  if (\"Fail to compute hash\".equals(e.getMessage())) {\n    log.error(\"A batch jar is unreadable — check permissions, locks, or truncated files in \" + batchDir, e);\n    // block startup or repair the directory before retrying\n  } else { throw e; }\n}","preventionTips":["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"],"tags":["batch","md5","io-exception","file-read"],"backgroundTag":"file-read-failed","analyzedSha":"184c821202192afc1c599fc912d0889b69fffa53","analyzedAt":"2026-09-09T12:23:51.573Z","contentChangedAt":"2026-09-09T12:23:51.573Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}