eclipse-jdt / eclipse-jdt/eclipse.jdt.core
Create local variable fails in try-with-resource
- Dominant language
- Java
- Stars
- 237
- Forks
- 195
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 47
Description
In foo() method the 'create locale variable' for 'br' does not work, and never come up; instead we get 'Change to BufferedReader' which is wrong and produces bad code.
In bar() method it works for both variables 'br' and 'br2' declared inside try-with-resource.
All the comments are just be sure not to miss anything!
Tested with master from20250209. (commit: bb205800de7ce8cb98c273f74bd004d9b51789fd)
`package p;`
`import java.io.BufferedReader;`
`import java.nio.file.Files;`
`public class E {`
void foo() {
try (/* A */br /* B */ = /* C */Files.newBufferedReader(null)/* D */) { /* E */
} catch (Exception e) {
}
}
void bar() {
try (/* A */br /* B */ = /* C */Files.newBufferedReader(null)/* D */;
/* A2 */br2 /* B2 */ = /* C2 */Files.newBufferedReader(null)/* D2 */) { /* E2*/
} catch (Exception e) {
}
}
`}`
Contributor guide
Assessment
This issue has not been assessed yet.