SonarSource/sonarqube · error · IllegalStateException

Cannot write Elasticsearch yml settings file

Error message

Cannot write Elasticsearch yml settings file

What it means

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.

Solutions

  1. Check the nested IOException cause in the stack trace for the precise filesystem error (NoSpaceLeft, AccessDenied, NoSuchFile)
  2. Ensure the parent directory (typically conf or the ES work/temp dir) exists and is writable by the SonarQube user
  3. Free disk space if the log indicates no space left
  4. Restart SonarQube so it recreates its temp/work directories

Example fix

// before
$ ls -ld /opt/sonarqube/temp
dr--r--r-- 2 root root temp   # not writable
// after
chown -R sonar:sonar /opt/sonarqube/temp && chmod u+rwx /opt/sonarqube/temp
Defensive patterns

Strategy: try-catch

Validate before calling

Path dir = file.toPath().getParent();
if (dir == null || !Files.isDirectory(dir) || !Files.isWritable(dir))
  throw new IllegalStateException("Cannot write ES yml: directory missing or unwritable: " + dir);

Try / catch

try { ymlSettings.writeToYmlSettingsFile(file); } catch (IllegalStateException e) { log.error("Failed writing elasticsearch.yml: {}", e.getCause(), e.getCause()); throw e; }

Prevention

When it happens

Trigger: Files.write(file.toPath(), ...) throws IOException: target directory missing, no write permission, disk full, or the path is not writable by the process user.

Common situations: ES temp/work directory removed while running; read-only container filesystem; permission changes after upgrade; full disk on the server.

Understand the failure class

Background: "failed to write file", "Could not save figure", "Error saving remote file" — file write failed: causes and fixes across languages and libraries — this error's family across 38 libraries.

Related errors


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

Appendix: source

Thrown at server/sonar-main/src/main/java/org/sonar/application/es/EsYmlSettings.java:55

    """;

  private final Map<String, String> elasticsearchSettings;

  public EsYmlSettings(Map<String, String> elasticsearchSettings) {
    this.elasticsearchSettings = elasticsearchSettings;
  }

  public void writeToYmlSettingsFile(File file) {
    DumperOptions dumperOptions = new DumperOptions();
    dumperOptions.setPrettyFlow(true);
    dumperOptions.setDefaultFlowStyle(BLOCK);
    Yaml yaml = new Yaml(dumperOptions);
    String output = ELASTICSEARCH_YML_OPTIONS_HEADER + yaml.dump(elasticsearchSettings);
    try {
      Files.write(file.toPath(), output.getBytes(StandardCharsets.UTF_8));
    } catch (IOException e) {
      throw new IllegalStateException("Cannot write Elasticsearch yml settings file", e);
    }
  }
}

View on GitHub (pinned to 184c821202)