Skip to content
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

[FEATURE] @Synchronized should check and warn if j.u.c.l.Lock var #2360

Open
rzwitserloot opened this issue Feb 10, 2020 · 0 comments
Open

Comments

@rzwitserloot
Copy link
Collaborator

When using the explicit form of synchronized, e.g. @Synchronized("myVar"), try to detect (it's not a perfect science without resolution, but the vast majority are detectable without resolution) if the field being locked on is of a lock type. If so, warn, because that is exceedingly rarely what you actually wanted, and I can imagine a lombok user thinking that Synchronized("someLockVar") would instead acquire the lock at top of method, not relinquishing it until a finally block at bottom of method.

Example

import java.util.concurrent.locks.*;

public class Example {
    private final Lock lock = new ReentrantLock();

    @Synchronized("lock") public void foo() {}
}

This code should emit a warning: synchronizing on an instance of java.util.concurrent.locks.Lock; that is extremely unlikely to be what you wanted.

See also issue #610

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant