I would like to report a runtime exception I'm getting from java-frontend/src/main/java/org/sonar/java/model/JavaVersionImpl.java which I cannot figure out why it is occurring.
Any help resolving this would be appreciated. I need to be able to support JDK10 for the environments I use. Right now
SonarQube server Version 7.1 (build 11001)
Executing 'gradle sonarqube' results in:
> Task :sonarqube
Invalid java version (got "10"). The version will be ignored. Accepted formats are "1.X", or simply "X" (for instance: "1.5" or "5", "1.6" or "6", "1.7" or "7", etc.)
The application environment is gradle for a scala project.
Gradle 4.7
Build time: 2018-04-18 09:09:12 UTC
Revision: b9a962bf70638332300e7f810689cb2febbd4a6c
Groovy: 2.4.12
Ant: Apache Ant(TM) version 1.9.9 compiled on February 2 2017
JVM: 10.0.1 ("Oracle Corporation" 10.0.1+10)
OS: Mac OS X 10.13.4 x86_64
The relevant build.gradle entries:
plugins {
id "org.sonarqube" version "2.6.2"
}
apply plugin: 'java'
apply plugin: 'scala'
sonarqube {
properties {
property "sonar.projectName", "Scala :: $project.name"
property "sonar.projectKey", "$project.name"
property "sonar.languages", "scala"
property "sonar.sources", "src/main/scala,src/integration/scala"
property "sonar.java.source", 10
property "sonar.java.target", 10
property "sonar.java.binaries", "build/classes/scala/main,build/classes/scala/integration"
property "sonar.scoverage.reportPath", "build/reports/scoverage/scoverage.xml"
property "sonar.host.url", "http://127.0.0.1:9000"
}
}
It produces the same error if the source and target versions are not specified explicitly if I place quotes around the number "10" or if I use the string "1.10". I can make it not raise an exception if I set "sonar.java.source" and "sonar.java.target" to "1.9"
I wrote a bit of test code using the same logic as is in JavaVersionImpl.java and could not get it to throw a NumberFormatException unless the argument had quotation marks around it. Not sure if that's a red herring though.
package regex_test;
import java.lang.System.Logger;
public class RegexTest {
private static final Logger LOG = System.getLogger(RegexTest.class.getName());
public static void main(String[] args) {
String version = new String();
version = fromString(args[0]);
LOG.log(Logger.Level.INFO, "Version parsed: " + version);
}
public static String fromString(String javaVersion) {
try {
// javaVersion = javaVersion.replaceAll("\"|'|’|“|”", "");
String cleanedVersion = javaVersion.startsWith("1.") ? javaVersion.substring(2) : javaVersion;
int versionAsInt = Integer.parseInt(cleanedVersion);
return Integer.toString(versionAsInt);
} catch (NumberFormatException e) {
LOG.log(Logger.Level.WARNING, "Invalid java version (got \"" + javaVersion + "\"). "
+ "The version will be ignored. Accepted formats are \"1.X\", or simply \"X\" "
+ "(for instance: \"1.5\" or \"5\", \"1.6\" or \"6\", \"1.7\" or \"7\", etc.)");
return javaVersion;
}
}
}