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

Valid code doesn't compile

XMLWordPrintable

    • b134
    • x86
    • linux
    • Verified

      FULL PRODUCT VERSION :
      java version "1.6.0_24"
      Java(TM) SE Runtime Environment (build 1.6.0_24-b07)
      Java HotSpot(TM) 64-Bit Server VM (build 19.1-b02, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Ubuntu 10.10

      A DESCRIPTION OF THE PROBLEM :
      Given example doesn't compile. Funnily, all parts of code are essential.

      Minor changes allow it to compile:
      1. Compiles if inner class is removed
      2. Compiles if 'final' is removed from any single field of inner class
      3. Compiles if any single field of inner class is removed
      4. Compiles if any single field of inner class in initialized in field declaration and not in constructor
      5. Compiles if inner class is removed completely
      6. Compiles if "final" is removed from "item" variable

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Compile example code

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Code compiles
      ACTUAL -
      Code doesn't compile

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Main.java:8: variable bug might already have been assigned
          bug = 0;
          ^
      1 error

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      public class Main {

        private static void foo() {
          final int bug;
          while ("a".equals("b")) {
            final int item = 0;
          }
          bug = 0;
        }

        private static class Inner {
          private final int a;
          private final int b;

          public Inner() {
            this.a = 0;
            this.b = 0;
          }
        }
      }
      ---------- END SOURCE ----------

            mcimadamore Maurizio Cimadamore
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: