SonarSource/sonarqube · error

Cannot open file

Error message

Cannot open file 

What it means

AppSettingsLoaderImpl.loadPropertiesFile reads conf/sonar.properties from the detected home directory as UTF-8 into a Properties object. An IOException while opening or reading the file is wrapped in IllegalStateException 'Cannot open file <path>'; a missing file only logs a warning and returns empty properties.

Source

Thrown at server/sonar-main/src/main/java/org/sonar/application/config/AppSettingsLoaderImpl.java:176

      .filter(key -> MULTI_SERVER_LDAP_SETTINGS.stream().noneMatch(pattern -> key.matches(pattern.replace(".", "\\.").replace("*", "[^.]+"))))
      .sorted()
      .forEach(key -> LOG.warn(
        "Property '{}' is not a recognized system property. It cannot be managed from the UI or API when set here, and it may have no effect. Please check the documentation.",
        key));
  }

  /**
   * Loads the configuration file ${homeDir}/conf/sonar.properties.
   * An empty {@link Properties} is returned if the file does not exist.
   */
  private static Properties loadPropertiesFile(File homeDir) {
    Properties p = new Properties();
    File propsFile = new File(homeDir, "conf/sonar.properties");
    if (propsFile.exists()) {
      try (Reader reader = new InputStreamReader(new FileInputStream(propsFile), UTF_8)) {
        p.load(reader);
      } catch (IOException e) {
        throw new IllegalStateException("Cannot open file " + propsFile, e);
      }
    } else {
      LOG.warn("Configuration file not found: {}", propsFile);
    }
    return p;
  }
}

View on GitHub (pinned to 184c821202)

Solutions

  1. Fix permissions so the SonarQube process user can read conf/sonar.properties (chown/chmod, e.g. chmod 640)
  2. Verify the path is a regular readable file, not a directory or broken symlink (ls -l conf/sonar.properties)
  3. Check SELinux/AppArmor denials in audit logs and add appropriate rules or relabel the file (restorecon)
  4. Inspect the wrapped IOException cause in the stack trace for the precise OS-level error

Example fix

// before
-rw------- root root conf/sonar.properties   (service runs as 'sonarqube')
// after
chown sonarqube:sonarqube conf/sonar.properties
chmod 640 conf/sonar.properties
Defensive patterns

Strategy: try-catch

Validate before calling

File conf = new File(homeDir, "conf/sonar.properties");
if (conf.exists() && (!conf.isFile() || !conf.canRead())) {
  throw new IllegalStateException("sonar.properties exists but is not readable: " + conf);
}

Type guard

boolean isReadableFile(File f) {
  return f.isFile() && f.canRead();
}

Try / catch

try {
  settingsLoader = new AppSettingsLoaderImpl(...);
} catch (IllegalStateException e) {
  if (e.getMessage().startsWith("Cannot open file")) {
    log.error("Check permissions on conf/sonar.properties", e.getCause());
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling loadPropertiesFile when conf/sonar.properties exists but cannot be opened or read: permission denied for the process user, the path is a directory, or an I/O error occurs mid-read.

Common situations: sonar.properties owned by root while the service runs as another user, SELinux/AppArmor blocking read access, broken symlinks to the config file, or mount failures leaving a stale directory entry.

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


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