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

A bug in javac that prevents variable shadowing

    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
    • OS:
      generic

      Description



      Name: skT88420 Date: 08/16/99


      // Platform: Windows 98
      // java version "1.2.1"
      // Classic VM (build JDK-1.2.1-A, native threads)

      /*
      Bug: When I compile this source file the "javac" compiler gives me an error
      that the variable 'f' is already defined in this method (Line 21) when I
      think it shouldn't do that (variable shadowing! and 'f' in main() is not
      final so anonymous classes can't access it anyway!). To be sure about that,
      I recompiled this source file using Microsoft's "JVC" compiler and it didn't
      generate any errors. And the 'java' VM was able to interpret it.
      */

      public class CompilerBug {

          public static void main(String[] Args) {
          int f = 10;

              (new Test() {
                  public void test(int z) {
                  int f = 50; // Variable 'f' is already defined in this method!!!?

                      System.out.println(z + f);
                  }
              }).test(f);

          }

      }

      interface Test {
          public void test(int z);
      }
      (Review ID: 93838)
      ======================================================================

        Attachments

          Activity

            People

            Assignee:
            iris Iris Clark
            Reporter:
            skonchad Sandeep Konchady
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: