Skip to content

SONARJAVA-6721 Implement S9141: Intrinsic locks should not be used on "java.util.concurrent" objects - #5890

Open
NoemieBenard wants to merge 6 commits into
masterfrom
nb/sonarjava-6721-implement-S9141
Open

SONARJAVA-6721 Implement S9141: Intrinsic locks should not be used on "java.util.concurrent" objects#5890
NoemieBenard wants to merge 6 commits into
masterfrom
nb/sonarjava-6721-implement-S9141

Conversation

@NoemieBenard

@NoemieBenard NoemieBenard commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Summary by Gitar

  • New checks:
    • Implemented SynchronizedOnConcurrentObjectCheck (S9141) to detect synchronized blocks on java.util.concurrent objects
  • Tests and documentation:
    • Added rule metadata, HTML documentation, JSON definition, test samples, and verifier tests for S9141

This will update automatically on new commits.

@hashicorp-vault-sonar-prod

hashicorp-vault-sonar-prod Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

SONARJAVA-6721

@gitar-bot

gitar-bot Bot commented Aug 5, 2026

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

Implements rule S9141 to detect intrinsic locks used on java.util.concurrent objects, addressing the scope finding to correctly target all concurrent types. No issues found.

✅ 1 resolved
Edge Case: Rule flags all java.util.concurrent types, not just sync primitives

📄 java-checks/src/main/java/org/sonar/java/checks/SynchronizedOnConcurrentObjectCheck.java:48-54
isFromConcurrentPackage matches any type whose FQN starts with java.util.concurrent., so synchronized on concurrent collections (e.g. ConcurrentHashMap, CopyOnWriteArrayList, ConcurrentLinkedQueue) or utility types (Future, TimeUnit, ThreadLocalRandom) is also reported. Externally locking such objects is occasionally a legitimate pattern, so this may produce false positives beyond the synchronization primitives the RSPEC emphasizes. If the intent is truly the whole package this is fine; otherwise consider restricting to the lock/semaphore/latch/barrier/queue subtypes and adding compliant test cases for concurrent collections to document the intended scope.

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

@sonarqube-next

sonarqube-next Bot commented Aug 5, 2026

Copy link
Copy Markdown

@NoemieBenard
NoemieBenard marked this pull request as ready for review August 5, 2026 15:16
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.

1 participant