{"record":{"id":"ba22287e956129f1","repo":"SonarSource/sonarqube","slug":"cannot-open-file","errorCode":null,"errorMessage":"Cannot open file ","messagePattern":"Cannot open file ","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/sonar-main/src/main/java/org/sonar/application/config/AppSettingsLoaderImpl.java","lineNumber":176,"sourceCode":"      .filter(key -> MULTI_SERVER_LDAP_SETTINGS.stream().noneMatch(pattern -> key.matches(pattern.replace(\".\", \"\\\\.\").replace(\"*\", \"[^.]+\"))))\n      .sorted()\n      .forEach(key -> LOG.warn(\n        \"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.\",\n        key));\n  }\n\n  /**\n   * Loads the configuration file ${homeDir}/conf/sonar.properties.\n   * An empty {@link Properties} is returned if the file does not exist.\n   */\n  private static Properties loadPropertiesFile(File homeDir) {\n    Properties p = new Properties();\n    File propsFile = new File(homeDir, \"conf/sonar.properties\");\n    if (propsFile.exists()) {\n      try (Reader reader = new InputStreamReader(new FileInputStream(propsFile), UTF_8)) {\n        p.load(reader);\n      } catch (IOException e) {\n        throw new IllegalStateException(\"Cannot open file \" + propsFile, e);\n      }\n    } else {\n      LOG.warn(\"Configuration file not found: {}\", propsFile);\n    }\n    return p;\n  }\n}\n","sourceCodeStart":158,"sourceCodeEnd":184,"githubUrl":"https://github.com/SonarSource/sonarqube/blob/184c821202192afc1c599fc912d0889b69fffa53/server/sonar-main/src/main/java/org/sonar/application/config/AppSettingsLoaderImpl.java#L158-L184","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Fix permissions so the SonarQube process user can read conf/sonar.properties (chown/chmod, e.g. chmod 640)","Verify the path is a regular readable file, not a directory or broken symlink (ls -l conf/sonar.properties)","Check SELinux/AppArmor denials in audit logs and add appropriate rules or relabel the file (restorecon)","Inspect the wrapped IOException cause in the stack trace for the precise OS-level error"],"exampleFix":"// before\n-rw------- root root conf/sonar.properties   (service runs as 'sonarqube')\n// after\nchown sonarqube:sonarqube conf/sonar.properties\nchmod 640 conf/sonar.properties","handlingStrategy":"try-catch","validationCode":"File conf = new File(homeDir, \"conf/sonar.properties\");\nif (conf.exists() && (!conf.isFile() || !conf.canRead())) {\n  throw new IllegalStateException(\"sonar.properties exists but is not readable: \" + conf);\n}","typeGuard":"boolean isReadableFile(File f) {\n  return f.isFile() && f.canRead();\n}","tryCatchPattern":"try {\n  settingsLoader = new AppSettingsLoaderImpl(...);\n} catch (IllegalStateException e) {\n  if (e.getMessage().startsWith(\"Cannot open file\")) {\n    log.error(\"Check permissions on conf/sonar.properties\", e.getCause());\n  }\n  throw e;\n}","preventionTips":["Set conf/sonar.properties ownership to the service user (e.g. 640 sonarqube:sonarqube)","Avoid symlinks to configs on mounts that may fail at boot","Check SELinux/AppAudit policies for the config directory","Verify config file readability after any deployment or permission change"],"tags":["java","filesystem","configuration"],"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-14T05:17:10.506Z"}