Bug 84886

Summary: [compiler] compiled code wrong with ambiguous inner classes
Product: [Eclipse Project] JDT Reporter: Edoardo Comar <edoardo>
Component: CoreAssignee: Kent Johnson <kent_johnson>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 Flags: Olivier_Thomann: review+
Version: 3.1   
Target Milestone: 3.3 RC1   
Hardware: PC   
OS: Linux   
Whiteboard:
Attachments:
Description Flags
Proposed patch none

Description Edoardo Comar CLA 2005-02-10 09:28:15 EST
try compile and run the following code.
javac 1.5_01 signals an error in code.
eclipse 31M4 is happy to compile (with 1.4 scr/bin compliance)
but on running the code surprisingly MyFoo$Bar is not generated

----------------------------------
package com.foo;

public class OuterClass {

    public static void main(String[] args) {
        System.out.println(OuterClass.class);
        System.out.println(MyFoo.class);
        System.out.println(MyFoo$Bar.class);
        System.out.println(MyFoo.Bar.class);
        System.out.println(MyFoo$Bar.class==MyFoo.Bar.class);
        System.out.println(new MyFoo$Bar());
        System.out.println(new MyFoo.Bar());
    }
    
    static class MyFoo {
        static class Bar {
            public String toString() {
                return "MyFoo.Bar instance";
            }
        }
    }
    
    static class MyFoo$Bar {
        public String toString() {
            return "MyFoo$Bar instance";
        }
    }

 }
Comment 1 Philipe Mulet CLA 2005-04-07 10:28:20 EDT
Reproduced in M6.
Comment 2 Philipe Mulet CLA 2007-04-26 07:00:04 EDT
We do not check for this scenario, and should report
duplicateNestedType(memberContext)

Note that a variation of this scenario is the case where MyFoo$Bar is another toplevel type, and another one when defined in a different file.
Comment 3 Kent Johnson CLA 2007-05-01 15:18:19 EDT
The 2 cases where MyFoo$Bar is a secondary top-level type in the same file or in a different file are already detected as duplicates.

Need to look into the best place to detect the member type duplicate.
Comment 4 Kent Johnson CLA 2007-05-02 12:59:28 EDT
Created attachment 65637 [details]
Proposed patch
Comment 5 Olivier Thomann CLA 2007-05-07 14:11:21 EDT
Now we do report a duplicate nested type as javac.
Comment 6 Kent Johnson CLA 2007-05-07 14:43:15 EDT
Released into HEAD for 3.3 RC1
Comment 7 David Audel CLA 2007-05-15 06:36:18 EDT
Verified for 3.3RC1 using I20070515-0010