- Notifications
You must be signed in to change notification settings - Fork1.8k
Java/more thread safe initialisers#20910
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Pull request overview
This PR enhances Java thread safety analysis to recognize when fields are initialized with thread-safe types inside constructors, not just in field initializer expressions. This reduces false positives when fields are assigned thread-safe collections (likeConcurrentHashMap or synchronized maps) in constructors.
Key Changes:
- Added
initialValuepredicate to check both field initializers and constructor assignments - Modified
ExposedFieldclass to use the new predicate for more comprehensive thread-safety checking - Added comprehensive test coverage for the new functionality
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
java/ql/lib/semmle/code/java/ConflictingAccess.qll | Implements the core logic by addinginitialValue predicate and updatingExposedField to check constructor assignments |
java/ql/test/query-tests/ThreadSafe/examples/ThreadSafeInitializers.java | Adds test cases demonstrating thread-safe initialization patterns in constructors |
java/ql/test/query-tests/ThreadSafe/ThreadSafe.expected | Updates expected test results to include the new test case alert |
java/ql/src/change-notes/2025-11-25-thread-safe-initializers.md | Documents the enhancement in the release notes |
💡Add Copilot custom instructions for smarter, more guided reviews.Learn how to get started.
Uh oh!
There was an error while loading.Please reload this page.
Co-authored-by: Raúl Pardo <raul.pardo@protonmail.com>
Whne a fiels is assigned a safe type in a constructor,that field is not exposed.
52296d4 toefb6a79Compare
When a field is assigned a safe type in a constructor, that field is not exposed.