{"record":{"id":"ba6bef632b3c7f42","repo":"SonarSource/sonarqube","slug":"cannot-write-elasticsearch-yml-settings-file","errorCode":null,"errorMessage":"Cannot write Elasticsearch yml settings file","messagePattern":"Cannot write Elasticsearch yml settings file","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"server/sonar-main/src/main/java/org/sonar/application/es/EsYmlSettings.java","lineNumber":55,"sourceCode":"\n    \"\"\";\n\n  private final Map<String, String> elasticsearchSettings;\n\n  public EsYmlSettings(Map<String, String> elasticsearchSettings) {\n    this.elasticsearchSettings = elasticsearchSettings;\n  }\n\n  public void writeToYmlSettingsFile(File file) {\n    DumperOptions dumperOptions = new DumperOptions();\n    dumperOptions.setPrettyFlow(true);\n    dumperOptions.setDefaultFlowStyle(BLOCK);\n    Yaml yaml = new Yaml(dumperOptions);\n    String output = ELASTICSEARCH_YML_OPTIONS_HEADER + yaml.dump(elasticsearchSettings);\n    try {\n      Files.write(file.toPath(), output.getBytes(StandardCharsets.UTF_8));\n    } catch (IOException e) {\n      throw new IllegalStateException(\"Cannot write Elasticsearch yml settings file\", e);\n    }\n  }\n}\n","sourceCodeStart":37,"sourceCodeEnd":59,"githubUrl":"https://github.com/SonarSource/sonarqube/blob/184c821202192afc1c599fc912d0889b69fffa53/server/sonar-main/src/main/java/org/sonar/application/es/EsYmlSettings.java#L37-L59","documentation":"EsYmlSettings.writeToYmlSettingsFile dumps the computed Elasticsearch settings to elasticsearch.yml using SnakeYAML. If Files.write fails with an IOException it wraps it in this IllegalStateException, meaning the computed settings could not be persisted to the target file.","triggerScenarios":"Files.write(file.toPath(), ...) throws IOException: target directory missing, no write permission, disk full, or the path is not writable by the process user.","commonSituations":"ES temp/work directory removed while running; read-only container filesystem; permission changes after upgrade; full disk on the server.","solutions":["Check the nested IOException cause in the stack trace for the precise filesystem error (NoSpaceLeft, AccessDenied, NoSuchFile)","Ensure the parent directory (typically conf or the ES work/temp dir) exists and is writable by the SonarQube user","Free disk space if the log indicates no space left","Restart SonarQube so it recreates its temp/work directories"],"exampleFix":"// before\n$ ls -ld /opt/sonarqube/temp\ndr--r--r-- 2 root root temp   # not writable\n// after\nchown -R sonar:sonar /opt/sonarqube/temp && chmod u+rwx /opt/sonarqube/temp","handlingStrategy":"try-catch","validationCode":"Path dir = file.toPath().getParent();\nif (dir == null || !Files.isDirectory(dir) || !Files.isWritable(dir))\n  throw new IllegalStateException(\"Cannot write ES yml: directory missing or unwritable: \" + dir);","typeGuard":null,"tryCatchPattern":"try { ymlSettings.writeToYmlSettingsFile(file); } catch (IllegalStateException e) { log.error(\"Failed writing elasticsearch.yml: {}\", e.getCause(), e.getCause()); throw e; }","preventionTips":["Keep the ES work/temp directory writable by the service user","Monitor disk space on the SonarQube host","Do not run SonarQube on read-only container filesystems without a writable temp volume","After permission changes, restart cleanly so dirs are recreated"],"tags":["elasticsearch","io","file-write","yaml"],"backgroundTag":"file-write-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"}