-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Java: Added new query java/visible-for-testing-abuse
#20178
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 our terms of service and privacy 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
java/ql/src/Violations of Best Practice/Implementation Hiding/VisibleForTestingAbuse.ql
Fixed
Show fixed
Hide fixed
java/ql/src/Violations of Best Practice/Implementation Hiding/VisibleForTestingAbuse.ql
Fixed
Show fixed
Hide fixed
java/ql/src/Violations of Best Practice/Implementation Hiding/VisibleForTestingAbuse.ql
Fixed
Show fixed
Hide fixed
java/ql/src/Violations of Best Practice/Implementation Hiding/VisibleForTestingAbuse.ql
Fixed
Show fixed
Hide fixed
…sibleForTestingAbuse alerts
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 introduces a new CodeQL query java/visible-for-testing-abuse
to detect misuse of the @VisibleForTesting
annotation in production code. The query identifies cases where elements annotated with @VisibleForTesting
are accessed from production code outside their intended scope, which violates the annotation's purpose of only increasing visibility for testing.
- Added the main query implementation with logic to detect inappropriate access patterns based on visibility modifiers
- Created comprehensive test cases covering various scenarios including cross-package access, lambda usage, and inner classes
- Integrated the query into the Java code quality query suites
Reviewed Changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
java/ql/src/Violations of Best Practice/Implementation Hiding/VisibleForTestingAbuse.ql |
Main query implementation detecting misuse of @VisibleForTesting annotation |
java/ql/src/Violations of Best Practice/Implementation Hiding/VisibleForTestingAbuse.md |
Documentation explaining the rule's purpose and implementation details |
java/ql/test/query-tests/VisibleForTestingAbuse/*.java |
Comprehensive test cases covering various usage scenarios |
java/ql/test/query-tests/VisibleForTestingAbuse/VisibleForTestingAbuse.qlref |
Test configuration referencing the query |
java/ql/test/query-tests/VisibleForTestingAbuse/VisibleForTestingAbuse.expected |
Expected test results |
java/ql/integration-tests/java/query-suite/*.expected |
Updated query suite integration test expectations |
java/ql/src/Violations of Best Practice/Implementation Hiding/VisibleForTestingAbuse.ql
Outdated
Show resolved
Hide resolved
java/ql/src/Violations of Best Practice/Implementation Hiding/VisibleForTestingAbuse.ql
Outdated
Show resolved
Hide resolved
…VisibleForTestingAbuse.ql Co-authored-by: Copilot <[email protected]>
b2ba0d7
to
8708130
Compare
Added new query
java/visible-for-testing-abuse
.Initial MRVA 1000 run produced 5,108 results, after reducing false positives ended up with 2,611.
DCA run: https://github.com/github/codeql-dca-main/tree/data/Napalys/visible-for-tes__nightly-buildle__CustomSuite__1/reports
Autofix tends to remove
@VisibleForTesting
, but it may requires deeper refactoring in which case it may not be accepted as a good fix.