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

Read access to uninitialized final member is allowed before initialization.

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Duplicate
    • Affects Version/s: 6
    • Fix Version/s: None
    • Component/s: tools
    • Subcomponent:
    • CPU:
      x86
    • OS:
      linux

      Description

      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 ----------

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: