Skip to content

Conversation

@yoff
Copy link
Contributor

@yoff yoff commented Nov 25, 2025

When a field is assigned a safe type in a constructor, that field is not exposed.

Copilot AI review requested due to automatic review settings November 25, 2025 14:52
@yoff yoff requested a review from a team as a code owner November 25, 2025 14:52
Copilot finished reviewing on behalf of yoff November 25, 2025 14:55
Copy link
Contributor

Copilot AI left a 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 (like ConcurrentHashMap or synchronized maps) in constructors.

Key Changes:

  • Added initialValue predicate to check both field initializers and constructor assignments
  • Modified ExposedField class 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 adding initialValue predicate and updating ExposedField 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.

yoff and others added 3 commits November 25, 2025 18:10
Whne a fiels is assigned a safe type in a constructor,
that field is not exposed.
@yoff yoff force-pushed the java/more-thread-safe-initialisers branch from 52296d4 to efb6a79 Compare November 25, 2025 17:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant