SonarSource/sonarqube · error
Could not copy file:
Error message
Could not copy file:
What it means
copyFile copies a source file (e.g. ES keystore, HTTP SSL certificate) into the temporary Elasticsearch conf directory with Files.copy(REPLACE_EXISTING). An IOException (source unreadable, target unwritable) is wrapped in this IllegalStateException including the source path, aborting ES setup.
Source
Thrown at server/sonar-main/src/main/java/org/sonar/application/ProcessLauncherImpl.java:212
esInstallation.getTrustStorePassword().ifPresent(s -> keyStoreCli.store(TRUSTSTORE_PASSWORD_PROPERTY_KEY, s));
esInstallation.getKeyStorePassword().ifPresent(s -> keyStoreCli.store(KEYSTORE_PASSWORD_PROPERTY_KEY, s));
}
private static void setupElasticsearchHttpEncryption(EsInstallation esInstallation, EsKeyStoreCli keyStoreCli) {
if (esInstallation.isHttpEncryptionEnabled()) {
String esConfPath = esInstallation.getConfDirectory().getAbsolutePath();
Path httpKeyStoreLocation = esInstallation.getHttpKeyStoreLocation();
copyFile(httpKeyStoreLocation, Paths.get(esConfPath, httpKeyStoreLocation.toFile().getName()));
esInstallation.getHttpKeyStorePassword().ifPresent(s -> keyStoreCli.store(HTTP_KEYSTORE_PASSWORD_PROPERTY_KEY, s));
}
}
private static void copyFile(Path from, Path to) {
try {
Files.copy(from, to, StandardCopyOption.REPLACE_EXISTING);
} catch (IOException e) {
throw new IllegalStateException("Could not copy file: " + from, e);
}
}
private static void storeElasticsearchLog4j2Properties(EsInstallation esInstallation) {
try (FileOutputStream fileOutputStream = new FileOutputStream(esInstallation.getLog4j2PropertiesLocation())) {
esInstallation.getLog4j2Properties().store(fileOutputStream, "log4j2 properties file for ES bundled in SonarQube");
} catch (IOException e) {
throw new IllegalStateException("Failed to write ES configuration files", e);
}
}
private <T extends JvmOptions> Process launchJava(JavaCommand<T> javaCommand) {
ProcessId processId = javaCommand.getProcessId();
try {
ProcessBuilder processBuilder = create(javaCommand);
logLaunchedCommand(javaCommand, processBuilder);
return processBuilder.start();
} catch (Exception e) {View on GitHub (pinned to 184c821202)
Solutions
- Verify the source file path in the message exists and is readable by the sonarqube user.
- Fix permissions on the ES temp conf destination directory.
- Re-check sonar.security / HTTPS keystore and certificate configuration properties.
- Ensure the source path is a file, not a directory or symlink to a missing target.
Example fix
// before sonar.web.https.keyStore=/etc/ssl/certs/nonexistent.p12 // after sonar.web.https.keyStore=/etc/sonarqube/keystore.p12 # verified readable
Defensive patterns
Strategy: validation
Validate before calling
Path from = Paths.get(keystoreProp);
if (!Files.isRegularFile(from) || !Files.isReadable(from)) {
throw new IllegalStateException("Certificate/keystore missing or unreadable: " + from);
} Try / catch
try { launcher.launch(...); } catch (IllegalStateException e) { if (e.getMessage().startsWith("Could not copy file:")) { verifySourcePath(e); } } Prevention
- Verify certificate/keystore paths exist and are readable before startup.
- Keep TLS material under a stable, service-readable directory.
- Update sonar properties whenever certificates are rotated or moved.
When it happens
Trigger: setupElasticsearchAuthentication() or setupElasticsearchHttpEncryption() -> copyFile() when the source file (cert/keystore) cannot be read or the destination in the ES temp conf dir cannot be written.
Common situations: Misconfigured sonar.auth.keystore / TLS certificate paths pointing at missing or unreadable files; permission problems in the temp conf dir; certificate file deleted or renamed after configuration.
Understand the failure class
Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.
Related errors
- Could not delete Elasticsearch temporary conf directory
- Failed to create temporary configuration directory [%s]
- Failed to write ES configuration files
- Cannot write Elasticsearch jvm options file
- Can not write to file
AI-assisted analysis of SonarSource/sonarqube@184c821202 (2026-09-09).
Data as JSON: /api/errors/f1400473f944f2f9.
Report an issue: GitHub.