SONARJAVA-6661 Fix Guava ruling with SonarQube 2026.4#5827
Conversation
ed769b0 to
3b2beeb
Compare
3b2beeb to
098e825
Compare
There was a problem hiding this comment.
I will approve the PR but this guava test looks dodgy to me.
- It is green if we remove the clean package goals and the sonar goal but keeping
sonar.java.sourceas Java 17 (see #5830) - The Java language version for this snapshot of the guava project is Java 8. So I am assuming that Java 17 is used here because we have been analyzing this project against the semantics of JDK 17 instead of JDK 8 for a while.
It is probably worth revisiting this test next time orchestrator is upgraded.
Co-authored-by: Dorian Burihabwa <75226315+dorian-burihabwa-sonarsource@users.noreply.github.com>
Removed unused import for ArrayList.
|
Code Review ✅ Approved 1 resolved / 1 findingsLimits the Java 17 override to the compilation goal, ensuring the scanner runs on the required Java 21 runtime. This resolves the property collision issue that triggered runtime rejection. ✅ 1 resolved✅ Bug: java.version=17 in goals still reaches the scanner goal
OptionsAuto-apply is off → Gitar will not commit updates to this branch. Comment with these commands to change the behavior for this request:
Was this helpful? React with 👍 / 👎 | Gitar |





Part of
Description
The Guava ruling passed
-Djava.version=17to both its compilation and scanner goals. Scanner Engine 13.3 and newer interprets that Maven property as the scanner runtime version and rejects it, even though Maven is already running on Java 21.Limit the Java 17 override to Guava compilation and run the scanner goal with the actual Java 21 runtime version.
Root cause
The ruling workflow already selects Java 21, and the failing job confirms that Maven runs from a Java 21 runtime. The failure is caused by a property collision rather than by selecting a Java 17 installation:
java.versionproperty as the compiler source and target level.-Djava.version=17so Guava is compiled as Java 17 code.java.versionto the in-process scanner.This became visible when
LATEST_RELEASEchanged from SonarQube 2026.3.1 with Scanner Engine 12.30.0, which only warned, to SonarQube 2026.4 with Scanner Engine 13.4.1, which rejects scanner runtimes below Java 21.Why compilation and scanner runtime remain separate
The SonarQube change ends support for running the scanner JVM on Java 17. It does not end support for analyzing projects whose source or bytecode targets Java 17. Keeping Guava compiled for Java 17 preserves ruling coverage for Java 17 projects, while running the scanner itself on Java 21 satisfies the new runtime requirement.
Removing Java 17 from
mise.tomlwould not fix this failure. That file makes several JDKs available, while the workflow explicitly selects Java 21. The misleading Java 17 value comes from the Maven property passed to both goals.Moving Guava compilation to Java 21 would also avoid the failure, but it would intentionally drop this Java 17 analysis coverage and could change ruling results. That should be a separate support-policy decision rather than an incidental consequence of the scanner runtime upgrade.
Fix
-Djava.version=17only to the Guavaclean packagegoal.java.versionoverride. The goals use a mutableArrayListbecause Orchestrator's varargssetGoals()creates a fixed-size list thataddSonarGoal()cannot append to.sonar.java.source=17explicitly. Once compilation and scanning are separated, the scanner otherwise reads Guava's original Java 8 POM setting, which changes rule behavior and produced 1,482 ruling differences. This property preserves the existing Java 17 analysis semantics without misrepresenting the scanner JVM runtime.Validation
mvn -pl its/ruling -am -DskipTests test-compileon Java 26LATEST_RELEASE-Djava.version=17.java.versionoverride and reports Java 21.sonar.java.source=17and no ruling differences.