eclipse-jdt / eclipse-jdt/eclipse.jdt.core
[TBD] Section 14.22: Clarify that reachability applies to constructor invocations
- Dominant language
- Java
- Stars
- 237
- Forks
- 195
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 47
Description
Ref: https://bugs.openjdk.org/browse/JDK-8370899
Description reproduced verbatim:
With Flexible Constructor Bodies, it becomes possible for an explicit constructor invocation to be unreachable. The current rule in 14.22 does not apply to constructor invocations, because they are not *statements*:
"It is a compile-time error if a statement cannot be executed because it is unreachable."
Besides stating the error condition, I think the section will need to add some rules about when an explicit constructor invocation is reachable.
javac properly enforces the rule, rejecting an unreachable explicit constructor invocation:
class C {
C() {
throw new RuntimeException();
super();
}
}
From ECJ pov, ECJ also flags error:
See the comment on the JDK bug as well about flagging / not flagging the unreachable info on implicit statements.
---snip---
It also seems that reachability is neither specified nor enforced for the implicit code at the end of a compact constructor?
jshell> record Foo(int i, int j) {
...> public Foo {
...> throw new RuntimeException();
...> }
...> }
| created record Foo
This seems like it's probably a bug, but I guess there's a design question about whether implicit code is subject to reachability rules.
The description of the implicit code (8.10.4.2) is more behavioral than syntax-oriented, so maybe you could argue there's no implicit statement here that would be subject to reachability rules?
"all component fields of the record class are implicitly initialized to the values of the corresponding formal parameters. The component fields are initialized in the order that the corresponding record components are declared in the record header"
---snip---
Putting @stephan-herrmann and myself as owners so that this can be just tracked.
At this point: No Action Required, However flagging this to Keep in the Radar.
Contributor guide
Assessment
This issue has not been assessed yet.