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

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

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Won't Fix
    • Affects Version/s: 1.2.1
    • Fix Version/s: None
    • Component/s: tools
    • Subcomponent:
    • CPU:
      generic, x86
    • OS:
      generic, windows_nt

      Description

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

        Attachments

          Activity

            People

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

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: