Skip to content

Commit fd366a7

Browse files
SCANJLIB-246 Improve the error message when the JRE provisioning is bypassed and uses a version of Java too old
1 parent b4327fa commit fd366a7

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

lib/src/main/java/org/sonarsource/scanner/lib/internal/facade/forked/JavaRunner.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@
3636
public class JavaRunner {
3737
private static final Logger LOG = LoggerFactory.getLogger(JavaRunner.class);
3838

39+
private static final String JRE_VERSION_ERROR = "The version of the custom JRE provided to the SonarScanner using the 'sonar.scanner.javaExePath' parameter is incompatible " +
40+
"with your SonarQube target. You may need to upgrade the version of Java that executes the scanner. " +
41+
"Refer to https://docs.sonarsource.com/sonarqube-community-build/analyzing-source-code/scanners/scanner-environment/general-requirements/ for more details.";
42+
3943
private final Path javaExecutable;
4044
private final JreCacheHit jreCacheHit;
4145

@@ -68,6 +72,11 @@ public boolean execute(List<String> args, @Nullable String input, Consumer<Strin
6872
var exitCode = process.waitFor();
6973
stdoutConsummer.join();
7074
stdErrConsummer.join();
75+
76+
if (stdErrConsummer.hasUnsupportedClassVersionError()) {
77+
LOG.error(JRE_VERSION_ERROR);
78+
}
79+
7180
if (exitCode != 0) {
7281
LOG.debug("Java command exited with code {}", process.exitValue());
7382
return false;
@@ -86,6 +95,7 @@ public Path getJavaExecutable() {
8695
private static class StreamGobbler extends Thread {
8796
private final InputStream inputStream;
8897
private final Consumer<String> consumer;
98+
private boolean unsupportedClassVersionError = false;
8999

90100
public StreamGobbler(InputStream inputStream, Consumer<String> consumer) {
91101
this.inputStream = inputStream;
@@ -95,7 +105,17 @@ public StreamGobbler(InputStream inputStream, Consumer<String> consumer) {
95105
@Override
96106
public void run() {
97107
new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8)).lines()
98-
.forEach(consumer);
108+
.forEach(line -> {
109+
if (line.contains("UnsupportedClassVersionError")) {
110+
unsupportedClassVersionError = true;
111+
}
112+
consumer.accept(line);
113+
});
99114
}
115+
116+
public boolean hasUnsupportedClassVersionError() {
117+
return unsupportedClassVersionError;
118+
}
119+
100120
}
101121
}

lib/src/test/java/org/sonarsource/scanner/lib/ScannerEngineBootstrapperTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -403,15 +403,15 @@ void should_set_deprecated_ssl_properties() {
403403

404404
when(httpConfig.getSslConfig())
405405
.thenReturn(new SslConfig(
406-
new CertificateStore(Paths.get("some/keystore.p12"), "keystorePass"),
407-
new CertificateStore(Paths.get("some/truststore.p12"), "truststorePass")));
406+
new CertificateStore(Paths.get("some", "keystore.p12"), "keystorePass"),
407+
new CertificateStore(Paths.get("some", "truststore.p12"), "truststorePass")));
408408

409409
underTest.adaptDeprecatedPropertiesForInProcessBootstrapping(Map.of(), httpConfig);
410410

411411
assertThat(System.getProperties()).contains(
412-
entry("javax.net.ssl.keyStore", "some/keystore.p12"),
412+
entry("javax.net.ssl.keyStore", Paths.get("some", "keystore.p12").toString()),
413413
entry("javax.net.ssl.keyStorePassword", "keystorePass"),
414-
entry("javax.net.ssl.trustStore", "some/truststore.p12"),
414+
entry("javax.net.ssl.trustStore", Paths.get("some", "truststore.p12").toString()),
415415
entry("javax.net.ssl.trustStorePassword", "truststorePass"));
416416
}
417417

0 commit comments

Comments
 (0)