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

final variable incorrectly reported as might been assigned to

XMLWordPrintable

    • x86
    • linux

      FULL PRODUCT VERSION :
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_05-b05)
      Java HotSpot(TM) Client VM (build 1.5.0_05-b05, mixed mode, sharing)


      ADDITIONAL OS VERSION INFORMATION :
      Linux solo 2.6.13.2 #5 Tue Sep 20 07:48:30 CEST 2005 i686 AMD Athlon(TM) XP 2100+ AuthenticAMD GNU/Linux


      A DESCRIPTION OF THE PROBLEM :
      javac rejects valid code. Please see the code sample below for reproducing the problem.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Compile the code sample below with

      javac Test.java

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The source should compile without any error message.
      ACTUAL -
      >javac Test.java
      Test.java:30: variable k might already have been assigned
              k = 0;
              ^
      1 error


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.util.*;

      final class Test
      {
          enum Test1 { TEST }

          final static class Foo
          {
              final boolean a;
              final Object b;
              final boolean c;

              Foo()
              {
                  a = true;
                  b = null;
                  c = false;
              }
          }

          final private int k;

          Test()
          {
              for (final Test1 category : EnumSet.allOf(Test1.class))
              {
                  final int i = 0;
              }

              k = 0;
          }
      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      Removing the 'final' modifier in the for-Block i.e. using

      int i = 0;

      instead of

      final int i = 0;

      is a work-around.

      Making the variable 'k' not final is also a work-around.

            jjg Jonathan Gibbons
            jssunw Jitender S (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: