eclipse-jdt / eclipse-jdt/eclipse.jdt.core
ECJ is too clever while infering generic types with Exceptions
- Dominant language
- Java
- Stars
- 237
- Forks
- 195
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 47
Description
The following class compiles and the test runs fine inside Eclipse but does not compile with `javac`. While I like that `ecj` can perfectly understand my intension, it seems to be inferring too much, as the code would not compile elsewhere.
```java
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertThrowsExactly;
import java.io.IOException;
import java.util.function.Supplier;
import org.junit.jupiter.api.Test;
public class MinimalTest {
public T supply(Supplier supplier) {
return supplier.get();
}
public @FunctionalInterface interface BadSupplier1 {
T get() throws X1;
}
public T supply(Class x1, BadSupplier1 supplier) throws X1 {
return supplier.get();
}
public @FunctionalInterface interface BadSupplier2 {
T get() throws X1, X2;
}
public T supply(Class x1, Class x2, BadSupplier2 supplier) throws X1, X2 {
return supplier.get();
}
public @Test void test() {
assertDoesNotThrow(() -> supply(() -> null));
assertThrowsExactly(IOException.class, () -> supply(IOException.class, () -> {
throw new IOException("To be expected");
}));
assertThrowsExactly(ClassNotFoundException.class, () -> supply(ClassNotFoundException.class, () -> {
throw new ClassNotFoundException("To be expected");
}));
assertThrowsExactly(IOException.class, () -> supply(IOException.class, IOException.class, () -> {
throw new IOException("To be expected");
}));
assertThrowsExactly(ClassNotFoundException.class, () -> supply(ClassNotFoundException.class, ClassNotFoundException.class, () -> {
throw new ClassNotFoundException("To be expected");
}));
// BREAKS ON NEXT LINE in javac but compiles and runs fine with ecj
assertThrowsExactly(IOException.class, () -> supply(IOException.class, ClassNotFoundException.class, () -> {
throw new IOException("To be expected");
}));
}
}
```
Contributor guide
Assessment
This issue has not been assessed yet.