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

Read access to uninitialized final member is allowed before initialization.

XMLWordPrintable

    • x86
    • linux

      FULL PRODUCT VERSION :
      java 1.6.0_01
      javac 1.6.0_01

      ADDITIONAL OS VERSION INFORMATION :
      Linux apollo 2.6.21.5-apollo #2

      A DESCRIPTION OF THE PROBLEM :
      If I declare a final (non-static) member inside a class and I do not initialize it, I still can access it inside the constructor just before initializing it. (It has null value.)

      private final String member;

      <constructor>() {
      if (this.member != null)
      this.member = "non-null";
      else
      this.member = "null";
      }

      After creation member has the value "null"...


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      I would expect to receive a compiler error...

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      class Bug
      {
      public Bug() {
      if (this.member != null)
      this.member = "non-null";
      else
      this.member = "null";
      }

      private final String member;

      public static void main(String[] arg) {
      System.out.println(new Bug().member);
      }
      }

      ---------- END SOURCE ----------

            sadayapalam Srikanth Adayapalam (Inactive)
            ryeung Roger Yeung (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: