JDK-4344812 : Inner class of anonymous class overwrites local class with the same name
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 1.3.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: solaris_7
  • CPU: sparc
  • Submitted: 2000-06-12
  • Updated: 2000-06-27
  • Resolved: 2000-06-27
Related Reports
Duplicate :  
Relates :  
Description

Name: inR10064			Date: 06/12/2000



Javac (build 1.3.0-C (fcs)) compiles the source icls02001.java (see below) 
without complains but classfile for inner class IC of anonymous class overwrites 
classfile for local class IC. So execution of example fails with the message :

___ java -showversion -cp clss icls02001
java version "1.3.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
Java HotSpot(TM) Client VM (build 1.3.0-C, interpreted mode)

Exception in thread "main" java.lang.NoSuchMethodError
	at icls02001.get(icls02001.java:18)
	at icls02001.main(icls02001.java:4)


Local class IC obtains full name icls02001$1$IC and the same name 
is constructed for second class IC because its outer class is anonymous 
and it in turn gets the name icls02001$1.

Oldjavac and compilers in previous jdk report errors on this valid source 
( see #4196251, closed now ).

___ oldjavac -J-showversion -d clss icls02001.java
java version "1.3.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
Java HotSpot(TM) Client VM (build 1.3.0-C, interpreted mode)

icls02001.java:23: Class icls02001. 1.IC already defined in icls02001.java.
        class IC {
              ^
icls02001.java:18: No enclosing instance of local class icls02001. 1 is in scope; an explicit one must be provided when creating inner class icls02001. 1.IC, as in "outer. new Inner()" or "outer. super()".
        return new IC();
               ^
icls02001.java:18: Incompatible type for constructor. Can't convert icls02001 to icls02001.1.
        return new IC();
               ^
3 errors



New JCK (Tweety) test 

lang/ICLS/icls020/icls02001/icls02001.html

written after #4196251 will be excluded with the number of reported bug.
Note that icls02001.java doesn't contain names with '$' char so this case 
differs from the matter of #4302890 (Synopsis: declared/synthetic class 
name conflict undetected).


--------------------------------------===  icls02001.java
public class icls02001 {

    public static void main(String argv[]) {
        Object ref = new icls02001().get();

        System.out.println("ref   = " + ref);
        System.out.println("stRef = " + stRef);
    }

    String loc = "local class";
    
    Object get() {
        class IC {
            public String toString() {
                return loc;
            }
        }
        return new IC();
    }

    static Object stRef = new Object() {
	String inr;
        class IC {
            public String toString() {
                return inr;
            }
        }
        public String toString() {
            inr = "local class";
            return "anonymous with " + new IC();
        }
    };
}

--------------------------------------===

======================================================================

Comments
EVALUATION 1.4.0beta-b20 gives the following error, similar to earlier 1.2 behavior: icls02001.java:23: duplicate class: IC class IC { ^ icls02001.java:30: cannot resolve symbol symbol: class IC return "anonymous with " + new IC(); ^ 2 errors A partial fix was made for 4302890 which had the side-effect of causing examples such as this to be rejected, as they were previously, rather than generating incorrect code. A complete solution remains to be implemented. There are two distinct cases given in 4302890 -- this is the second one. william.maddox@Eng 2000-06-26
26-06-2000