Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8370899

14.22: Clarify that reachability applies to constructor invocations

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • None
    • 25
    • specification

      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();
          }
      }

      | Error:
      | unreachable statement
      | super();
      | ^------^

            gbierman Gavin Bierman
            dlsmith Dan Smith
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: