google / google/error-prone

MustBeClosedChecker - False positive due to variable declaration without expression

Open
#3,346 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
7.2k
Forks
820
Avg merge
5h 9m
Merged PRs (30d)
50

Description

Looking at [this line](https://github.com/google/error-prone/blob/d19024b059d9db804045fdc992c9f6f3ff073769/core/src/main/java/com/google/errorprone/bugpatterns/AbstractMustBeClosedChecker.java#L303) of code, I believe that we should be looking for the next statement that is not an empty variable declaration.

For example:
```
Closeable closeable = getCloseable();
@var SomeVariable x;
try {
// code here
} finally {
closeable.close();
}
```

I believe that since there is no expression on the RHS of the SomeVariable declaration, that the closeable is indeed guaranteed to be closed.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.