Skip to content

Commit e8711ed

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

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

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

Lines changed: 19 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 Java version provided to the SonarScanner is incompatible with your SonarQube target. " +
40+
"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

@@ -70,6 +74,11 @@ public boolean execute(List<String> args, @Nullable String input, Consumer<Strin
7074
var exitCode = process.waitFor();
7175
stdoutConsummer.join();
7276
stdErrConsummer.join();
77+
78+
if (stdErrConsummer.getMessages().stream().anyMatch(msg -> msg.contains("UnsupportedClassVersionError"))) {
79+
LOG.error(JRE_VERSION_ERROR);
80+
}
81+
7382
if (exitCode != 0) {
7483
LOG.debug("Java command exited with code {}", process.exitValue());
7584
return false;
@@ -88,16 +97,25 @@ public Path getJavaExecutable() {
8897
private static class StreamGobbler extends Thread {
8998
private final InputStream inputStream;
9099
private final Consumer<String> consumer;
100+
private final List<String> messages;
91101

92102
public StreamGobbler(InputStream inputStream, Consumer<String> consumer) {
93103
this.inputStream = inputStream;
94104
this.consumer = consumer;
105+
this.messages = new ArrayList<>();
95106
}
96107

97108
@Override
98109
public void run() {
99110
new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8)).lines()
100-
.forEach(consumer);
111+
.forEach(line -> {
112+
messages.add(line);
113+
consumer.accept(line);
114+
});
115+
}
116+
117+
private List<String> getMessages() {
118+
return messages;
101119
}
102120
}
103121
}

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

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

380380
when(httpConfig.getSslConfig())
381381
.thenReturn(new SslConfig(
382-
new CertificateStore(Paths.get("some/keystore.p12"), "keystorePass"),
383-
new CertificateStore(Paths.get("some/truststore.p12"), "truststorePass")));
382+
new CertificateStore(Paths.get("some", "keystore.p12"), "keystorePass"),
383+
new CertificateStore(Paths.get("some", "truststore.p12"), "truststorePass")));
384384

385385
underTest.adaptDeprecatedPropertiesForInProcessBootstrapping(Map.of(), httpConfig);
386386

387387
assertThat(System.getProperties()).contains(
388-
entry("javax.net.ssl.keyStore", "some/keystore.p12"),
388+
entry("javax.net.ssl.keyStore", Paths.get("some", "keystore.p12").toString()),
389389
entry("javax.net.ssl.keyStorePassword", "keystorePass"),
390-
entry("javax.net.ssl.trustStore", "some/truststore.p12"),
390+
entry("javax.net.ssl.trustStore", Paths.get("some", "truststore.p12").toString()),
391391
entry("javax.net.ssl.trustStorePassword", "truststorePass"));
392392
}
393393

0 commit comments

Comments
 (0)