eclipse-jdt / eclipse-jdt/eclipse.jdt.core

[TWR] ECJ generated code fails to close resources used in try

Open
#3,259 0 comments 0 reactions 1 assignee Claimed by @srikanth-sankaran View on GitHub
Dominant language
Java
Stars
237
Forks
195
Avg merge
1d 12h
Merged PRs (30d)
47

Description

This program when compiled with javac prints

```
Resource is closed
finally
```

whilke with ECJ 4.30 and on master/HEAD just prints `finally`

On 4.25, ECJ crashes with symptoms similar to https://github.com/eclipse-jdt/eclipse.jdt.core/issues/3258

```
public class X implements AutoCloseable {

public void close() throws Exception {
System.out.println("Resource is closed");
}

public static void foo(String[] args) {

for (String arg : args) {
try (X x = new X()) {
if (args.length == 1) {
System.out.println("Broken!");
break;
} else {
throw new Exception("Checking if resource is closed");
}
} finally {
System.out.println("finally");
break;
}
}
}

public static void main(String[] args) {
foo(new String[] { "Hello", "World" });
}
}

```

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.