-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Java: Improve qhelp for java/unreleased-lock and add lock type exclusion
#21226
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
Java: Improve qhelp for java/unreleased-lock and add lock type exclusion
#21226
Conversation
|
QHelp previews: java/ql/src/Likely Bugs/Concurrency/UnreleasedLock.qhelpUnreleased lockWhen a thread acquires a lock it must make sure to unlock it again; failing to do so can lead to deadlocks. If a lock allows a thread to acquire it multiple times, for example Any class that has both RecommendationIt is recommended practice always to immediately follow a call to ExampleThe typical pattern for using locks safely looks like this: public void m() {
lock.lock();
// A
try {
// ... method body
} finally {
// B
lock.unlock();
}
}If any code that can cause a premature method exit (for example by throwing an exception) is inserted at either point References
|
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 pull request improves the java/unreleased-lock query by excluding lock types with names ending in "Pool" to reduce false positives. Pool classes typically manage collections of resources where lock/unlock methods operate on individual resources rather than the pool itself.
Changes:
- Added exclusion pattern to
LockTypeclass to filter out types with names ending in "Pool" - Updated documentation in comments and qhelp to clarify which classes are considered lock types
- Added test case to verify that Pool-suffixed classes are properly excluded from the query
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| java/ql/lib/semmle/code/java/Concurrency.qll | Added not this.getName().matches("%Pool") exclusion to LockType class and updated documentation comments |
| java/ql/test/query-tests/UnreleasedLock/UnreleasedLock.java | Added TestPool class and good11 test method to verify Pool classes are excluded |
| java/ql/lib/change-notes/2026-01-27-unreleased-lock-pools.md | Documented the change as a minor analysis improvement that reduces false positives |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
aschackmull
left a comment
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.
Sounds reasonable. 👍
Previously it was not clear that this query applies to any class with
lockandunlockmethods.I looked into whether to limit this to just classes which implement
java.util.concurrent.locks.Lock(which account for ~2/3 of alerts) but found that custom lock types were all TPs except the oneio.questdb.cairo.pool.WriterPool. I have now excluded types with names ending in "Pool" as they manage a collection of resources and thelockandunlockmethods may be called for different resources. And I've added a test for this.