Bug 84886 - [compiler] compiled code wrong with ambiguous inner classes
Summary: [compiler] compiled code wrong with ambiguous inner classes
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 3.3 RC1   Edit
Assignee: Kent Johnson CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-02-10 09:28 EST by Edoardo Comar CLA
Modified: 2007-05-15 06:36 EDT (History)
0 users

See Also:
Olivier_Thomann: review+


Attachments
Proposed patch (2.32 KB, patch)
2007-05-02 12:59 EDT, Kent Johnson CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
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