Skip to content

SONARJAVA-6661 Fix Guava ruling with SonarQube 2026.4#5827

Merged
vdiez merged 3 commits into
masterfrom
codex/fix-guava-ruling-java-version
Jul 22, 2026
Merged

SONARJAVA-6661 Fix Guava ruling with SonarQube 2026.4#5827
vdiez merged 3 commits into
masterfrom
codex/fix-guava-ruling-java-version

Conversation

@vdiez

@vdiez vdiez commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Part of

Description

The Guava ruling passed -Djava.version=17 to 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:

  • The Guava POM uses its java.version property as the compiler source and target level.
  • The ruling test overrides it with -Djava.version=17 so Guava is compiled as Java 17 code.
  • Maven exposes that user property as java.version to the in-process scanner.
  • Scanner Engine 13.3 and newer uses that property to validate its runtime and therefore believes that it is running on Java 17.

This became visible when LATEST_RELEASE changed 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.toml would 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

  • Apply -Djava.version=17 only to the Guava clean package goal.
  • Append Orchestrator's canonical scanner goal so scanning runs as a separate Maven invocation without the java.version override. The goals use a mutable ArrayList because Orchestrator's varargs setGoals() creates a fixed-size list that addSonarGoal() cannot append to.
  • Set sonar.java.source=17 explicitly. 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-compile on Java 26
  • Ruling QA without-sonarqube-project on Java 21 with SonarQube LATEST_RELEASE
    • Guava compilation runs separately with -Djava.version=17.
    • The scanner invocation has no java.version override and reports Java 21.
    • Analysis reports sonar.java.source=17 and no ruling differences.

@hashicorp-vault-sonar-prod hashicorp-vault-sonar-prod Bot changed the title Fix Guava ruling with SonarQube 2026.4 SONARJAVA-6661 Fix Guava ruling with SonarQube 2026.4 Jul 21, 2026
@hashicorp-vault-sonar-prod

hashicorp-vault-sonar-prod Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

SONARJAVA-6661

Comment thread its/ruling/src/test/java/org/sonar/java/it/JavaRulingTest.java Outdated
@vdiez
vdiez force-pushed the codex/fix-guava-ruling-java-version branch from ed769b0 to 3b2beeb Compare July 21, 2026 16:52
@vdiez
vdiez force-pushed the codex/fix-guava-ruling-java-version branch from 3b2beeb to 098e825 Compare July 21, 2026 17:02

@dorian-burihabwa-sonarsource dorian-burihabwa-sonarsource left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will approve the PR but this guava test looks dodgy to me.

  1. It is green if we remove the clean package goals and the sonar goal but keeping sonar.java.source as Java 17 (see #5830)
  2. 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.

Comment thread its/ruling/src/test/java/org/sonar/java/it/JavaRulingTest.java
vdiez and others added 2 commits July 22, 2026 18:32
Co-authored-by: Dorian Burihabwa <75226315+dorian-burihabwa-sonarsource@users.noreply.github.com>
Removed unused import for ArrayList.
@sonarqube-next

Copy link
Copy Markdown

@vdiez
vdiez merged commit dd68ed0 into master Jul 22, 2026
16 checks passed
@vdiez
vdiez deleted the codex/fix-guava-ruling-java-version branch July 22, 2026 16:59
@gitar-bot

gitar-bot Bot commented Jul 22, 2026

Copy link
Copy Markdown
Code Review ✅ Approved 1 resolved / 1 findings

Limits 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

📄 its/ruling/src/test/java/org/sonar/java/it/JavaRulingTest.java:208-210
Orchestrator runs all goals and properties in a single mvn invocation, producing roughly mvn clean package -Djava.version=17 sonar:sonar .... A -D on the Maven command line is a global user property parsed at CLI startup and applied to the entire session regardless of its position among the goals, so sonar:sonar still sees java.version=17 — exactly the situation the PR intends to avoid. This makes the change functionally equivalent to the old .setProperty("java.version","17") and likely does not fix the Scanner Engine 13.3+ rejection. To truly isolate the compile-time value, run compilation and the scanner as separate Maven invocations (or pass the target version via a compiler-specific property such as -Dmaven.compiler.release=17 rather than the global java.version). Note the PR was only validated with test-compile, so the scanner path was never exercised.

Options

Auto-apply is off → Gitar will not commit updates to this branch.
Display: compact → Showing less information.

Comment with these commands to change the behavior for this request:

Auto-apply Compact
gitar auto-apply:on         
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Gitar

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants