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

Compiler reports unreachable static initializers, contrary to JLS

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Won't Fix
    • Icon: P3 P3
    • None
    • 1.1.3
    • tools
    • None
    • sparc
    • solaris_2.5.1

      class B {
          static final int x;
          static { while (true) {} }
          static { x = 1; }
      }

      ==>

      Init4.java:4: Statement not reached.
          static { x = 1; }
                 ^
      Init4.java:4: Can't assign a second value to a blank final variable: x
          static { x = 1; }
                   ^

      ---

      The first error message is in violation of the JLS.
      (The second error is spurious, due to a bad error recovery, and is covered in
      a separate bug report.)

      According to JLS 14.19, "the block that is the body of a ... static
      initializer is reachable." In general, the detection of unreachable
      statements is performed within the body of a single constructor, method,
      or static initializer.

      It is not entirely clear that this should be an error, as the introduction
      of blank finals into the language changes the ground rules for the required
      compile-time flow analsyis. In the JLS, none of the required flow analysis
      (definite assignment, unreachable statements) operates at the class level,
      i.e., considering the effect of one field initialization or static initializer
      upon a successive one. With the introduction of blank finals, this policy
      has been changed.

      william.maddox@Eng 1997-07-10

            wmaddoxsunw William Maddox (Inactive)
            wmaddoxsunw William Maddox (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: