United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-4615601 : False detection of duplicate local class declaration

Details
Type:
Bug
Submit Date:
2001-12-19
Status:
Closed
Updated Date:
2003-04-12
Project Name:
JDK
Resolved Date:
2002-09-02
Component:
tools
OS:
solaris_8,windows_98
Sub-Component:
javac
CPU:
x86,generic
Priority:
P5
Resolution:
Fixed
Affected Versions:
1.4.0
Fixed Versions:
1.4.2 (mantis)

Related Reports
Duplicate:

Sub Tasks

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



Hardware and Software, Engineered to Work Together