alibaba / alibaba/p3c

此规则无法满足:锁【lock.lockInterruptibly】必须紧跟try代码块,且unlock要放到finally第一行。

Open
#653 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Kotlin
Stars
30.8k
Forks
8k
PR merge metrics
No merged PRs in 30d

Description

## 规约原文
锁【lock.lockInterruptibly】必须紧跟try代码块,且unlock要放到finally第一行。

## 问题描述
如下代码

`
Thread t2 = new Thread(() -> {
try {
lock.lockInterruptibly();
System.out.println("if lock thread is interrupted, it will run");
TimeUnit.SECONDS.sleep(5);
} catch (InterruptedException e) {
System.out.println("interrupted");
} finally {
lock.unlock();
}
});
`

lock.lockInterruptibly() 如果紧跟try,那么就没办法catch exception了,所以这条规则无法满足
## 修改建议

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by locating the rule that checks lock.lockInterruptibly and inspect how it handles the surrounding try, catch, and finally blocks. Reproduce the Java example from the issue, then identify the expected rule behavior before changing anything; done means the rule can distinguish valid exception handling from a real violation and its relevant checks pass.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
devtools, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.