Skip to content

[ISSUE #10817] Upgrade SpotBugs for JDK 21 compatibility - #10818

Merged
fuyou001 merged 1 commit into
apache:developfrom
fuyou001:agent/upgrade-spotbugs-jdk21
Aug 6, 2026
Merged

[ISSUE #10817] Upgrade SpotBugs for JDK 21 compatibility#10818
fuyou001 merged 1 commit into
apache:developfrom
fuyou001:agent/upgrade-spotbugs-jdk21

Conversation

@fuyou001

@fuyou001 fuyou001 commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Which Issue(s) This PR Fixes

Brief Description

Upgrade spotbugs-maven-plugin from 4.2.2 to 4.8.6.8 so that SpotBugs can run on JDK 21 while retaining JDK 8 compatibility.

The old plugin fails on JDK 21 because it invokes the deprecated Security Manager API and bundles an ASM version that cannot analyze Java 21 class files. This change also removes the obsolete spotbugsXmlOutput parameter, which is not supported by 4.8.6.8.

The newer SpotBugs version detects several High-priority DMI_RANDOM_USED_ONLY_ONCE findings. Replace those one-shot Random instances with ThreadLocalRandom, or reuse the existing shared Random in RandomUtil, while preserving the original value ranges and behavior.

How Did You Test This Change?

  • JDK 21: mvn -B -ntp -Dstyle.color=never -DskipTests compile
  • JDK 8: mvn -B -ntp -Dstyle.color=never -DskipTests clean compile

Both full 19-module reactor builds completed successfully with Checkstyle and SpotBugs reporting no violations.

@fuyou001
fuyou001 marked this pull request as ready for review August 6, 2026 02:32
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 75.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 48.24%. Comparing base (2daf0e2) to head (29197c4).

Files with missing lines Patch % Lines
.../org/apache/rocketmq/store/kv/CompactionStore.java 0.00% 1 Missing ⚠️
Additional details and impacted files
@@              Coverage Diff              @@
##             develop   #10818      +/-   ##
=============================================
- Coverage      48.32%   48.24%   -0.09%     
+ Complexity     13516    13497      -19     
=============================================
  Files           1380     1380              
  Lines         101138   101135       -3     
  Branches       13120    13120              
=============================================
- Hits           48876    48792      -84     
- Misses         46298    46359      +61     
- Partials        5964     5984      +20     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@RockteMQ-AI RockteMQ-AI 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.

Summary

SpotBugs plugin upgrade from 4.2.2 → 4.8.6.8 for JDK 21 compatibility. The old plugin fails on JDK 21 due to deprecated Security Manager API and bundled ASM that can't analyze Java 21 class files.

The newer SpotBugs detects DMI_RANDOM_USED_ONLY_ONCE findings, and the PR correctly addresses them:

  • Benchmark BatchProducer / Producer: one-shot new Random(System.currentTimeMillis())ThreadLocalRandom.current()
  • MessageQueueSelector: one-shot new Random()ThreadLocalRandom.current()
  • NettyRemotingClient.initValueIndex(): one-shot new Random()ThreadLocalRandom.current()
  • CompactionStore: one-shot new Random(System.currentTimeMillis())ThreadLocalRandom.current()
  • RandomUtil: removes local Random rd that shadowed the class-level field — the loop now correctly uses the shared class-level rd

Removal of obsolete spotbugsXmlOutput parameter is also correct (not supported in 4.8.6.8).

All changes preserve original value ranges and behavior. Verified builds on both JDK 8 and JDK 21.


Automated review by github-manager-bot

@fuyou001
fuyou001 merged commit 51f9fcc into apache:develop Aug 6, 2026
10 of 11 checks passed

@RockteMQ-AI RockteMQ-AI 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.

Summary

Defensive fix with proper validation and test coverage. LGTM.


Automated review by github-manager-bot

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.

Upgrade spotbugs-maven-plugin for JDK 21 compatibility

6 participants