eclipse-jdt / eclipse-jdt/eclipse.jdt.core
False positive "Resource should be managed by try-with-resource"
- Dominant language
- Java
- Stars
- 237
- Forks
- 195
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 47
Description
The snippet below produces a false "Resource 'subject' should be managed by try-with-resource" diagnostic. Try-with-resources can only manage nested lifetimes, not intersecting or complex ones.
```java
class ResourceOfIntersectingLifetime implements Closeable {
public ResourceOfIntersectingLifetime(Closeable service) {
}
@Override
public void close() throws IOException {
}
public void afterOriginIsClosed() {
}
}
@Test
public void intersectingScopeManagedFalsePositive () throws IOException {
ResourceOfIntersectingLifetime subject = null; // Resource 'subject' should be managed by try-with-resource. False positive.
Path p = null;
try {
try (Closeable service = Files.newInputStream(p)) {
subject = new ResourceOfIntersectingLifetime(service);
}
subject.afterOriginIsClosed();
} finally {
if (subject != null) {
subject.close();
}
}
}
```
# Environment
Eclipse IDE for Eclipse Committers (includes Incubating components)
Version: 2026-03 RC1 (4.39.0 RC1)
Build id: 20260220-0259
OS: Mac OS X, v.26.3.1, aarch64 / cocoa
Java vendor: Oracle Corporation
Java runtime version: 25+36-3489
Java version: 25
*** Features:
org.eclipse.jdt (3.20.500.v20260219-1233) "Eclipse Java Development Tools"
Contributor guide
Assessment
This issue has not been assessed yet.