JDK-4615601 : False detection of duplicate local class declaration
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 1.4.0
  • Priority: P5
  • Status: Closed
  • Resolution: Fixed
  • OS: solaris_8,windows_98
  • CPU: generic,x86
  • Submitted: 2001-12-19
  • Updated: 2003-04-12
  • Resolved: 2002-09-02
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
1.4.2 mantisFixed
Related Reports
Duplicate :  
Description

Name: ddT132432			Date: 12/18/2001


FULL PRODUCT VERSION :
java version "1.4.0-beta3"
Java(TM) 2 Runtime Environment, Standard Edition (build
1.4.0-beta3-b84)
Java HotSpot(TM) Client VM (build 1.4.0-beta3-b84, mixed
mode)


FULL OPERATING SYSTEM VERSION :
Windows 98 [Version 4.10.1998]

ADDITIONAL OPERATING SYSTEMS :
All OS's - the problem is platform independent


A DESCRIPTION OF THE PROBLEM :
The javac compiler mistakenly reports a duplicate class
declaration in the example below, when a member class
inside an anonymous class shadows the declaration of a
local class by the same name. According to JLS 14.3, the
shadowing is legal since the two classes of the same simple
name are declared in different innermost enclosing classes.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. compile the program listed below


EXPECTED VERSUS ACTUAL BEHAVIOR :
Expected: The compiler should complete without error.

Actual: Compilation fails:
Foo.java:5: duplicate class: Local
        class Local {}
        ^
1 error


This bug can be reproduced always.

---------- BEGIN SOURCE ----------
class Foo {
  void foo() {
    class Local {} // local class
    new Object() {
      class Local {} // member class
    };
  }
}

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

CUSTOMER WORKAROUND :
Do not attempt to reuse names, even though it is legal.
(Review ID: 137418) 
======================================================================

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: mantis mantis-b02 FIXED IN: mantis mantis-b02 INTEGRATED IN: mantis mantis-b02 VERIFIED IN: mantis
2004-06-14

PUBLIC COMMENTS A flaw in the compiler's mechanism for generating flatnames for anonymous and local classes allowed the possibility of a clash. To repair the problem, javac now generates one fewer '$' in the name of each local class. In general, each java compiler is free to select its own name mangling mechanism for generating flatnames for anonymous and local classes.
2004-06-10

EVALUATION Right, a bug. ###@###.### 2002-02-01 Here is an appropriate regression test: // 4615601: False detection of duplicate local class declaration class T3 { boolean x1 = false; boolean x2 = false; void foo() { class Local {{ x1 = true; }} { new Local(); } new Object() { class Local {{ x2 = true; }} { new Local(); } }; } void check() { foo(); if (!x1) throw new Error("x1"); if (!x2) throw new Error("x2"); } public static void main(String[] args) { new T3().check(); } } ###@###.### 2002-05-21
2002-05-21