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

Invalid blank final error when inner class (using private final) initialized

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Won't Fix
    • Icon: P4 P4
    • None
    • 1.2.1
    • tools
    • generic, x86
    • generic, windows_nt

      Variable must be a private blank final.
      Variable must be used in inner class.

      Error message:

      % javac ES.java
      ES.java:2: Blank final variable 'session' may not have been initialized. It must be assigned a value in an initializer, or in every constructor.
          private final int session;
                                   ^
      1 error
      %

      This appears to be the minimal program to reproduce:

      class ES {
          private final int session;

          ES() {
      this.session = 5;
          }

          class Foo {
              int bar() {
                  return session;
              }
          }
      }




      Name: skT88420 Date: 06/23/99


      class A
      {
          static int a = 0 ;
      }

      class B
      {
          /* must be private and refer to another class's static member or our own "class" member (i.e. B.class);
           * doesn't happen if a constant is assigned to the variable;
           * static doesn't matter
           */

          private final int b = A.a ;

          /* static doesn't matter */
          class C
          {
              void f()
              {
                  int c = b ;
              }
          }

          /* javac says this variable "may not have been initialized" */
          final int i ;
          B(int i)
          {
              this.i = i ;
          }
      }


      ~$ javac Test.java
      Test.java:21: Blank final variable 'i' may not have been initialized. It must be assigned a value in
       an initializer, or in every constructor.
              final int i ;
                          ^
      1 error
      ~$

      This is similar to all the other blank final spurious uninitialized
      bugs (e.g 4218427, 4147610)
      (Review ID: 84702)
      ======================================================================

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

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: