NPE in javac 11.0.18 while infering exception type in lambda
Attila Kelemen
attila.kelemen85 at gmail.com
Fri May 12 20:21:52 UTC 2023
The following code causes javac to throw an NPE:
```
public class JavacBug {
interface MyFunction<E extends Throwable> {
Object apply(Object arg) throws E;
}
<E extends Throwable> Object withObj(MyFunction<E> f) throws E {
return f.apply("X");
}
void dummyCall(Object arg) {
}
void test() {
withObj(obj1 -> {
return withObj(obj2 -> {
dummyCall(obj1);
return null;
});
});
}
}
```
I have only tried this with 17 (aside from 11.0.18), but 17 compiles it fine.
The workaround to this issue is to explicitly declare the generic
parameter of the inner `withObj` call.
Attila
More information about the compiler-dev
mailing list