Bug 98120 - [compiler] dollar signs and anonymous classes confusion
Summary: [compiler] dollar signs and anonymous classes confusion
Status: CLOSED WONTFIX
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
: 188167 (view as bug list)
Depends on:
Blocks:
 
Reported: 2005-06-02 10:57 EDT by Andrew J Huff CLA
Modified: 2020-04-04 01:25 EDT (History)
1 user (show)

See Also:


Attachments
Proposed patch (955 bytes, patch)
2007-06-13 14:12 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 Andrew J Huff CLA 2005-06-02 10:57:39 EDT
Noticed while working on AspectJ bug 95344,

/////////////////////////////// with the following code
interface Main$1 {void hello();}

public class Main{
  public static void main(String [] args){
	  Main$1 anon = new Main$1()
            {public void hello(){System.out.println("hello world!");}};
	  anon.hello();
  }
}
//////////////////////////////////////////////////

javac produces the files:
Main$1.class
Main$2.class
Main.class

and when Main is ran it says:
hello world!

jdt in Eclipse 3.1RC1 produces the files:
Main$1.class
Main.class

and when Main is ran it says:
Exception in thread "main" java.lang.ClassCircularityError: Main$1
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
        at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
        at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
        at Main.main(Main.java:5)
Comment 1 Andrew J Huff CLA 2005-06-02 11:10:00 EDT
and now when I try running it it says

Exception in thread "main" java.lang.InstantiationError: Main$1
        at Main.main(Main.java:5)

weird.

Also:
having compiled the file in javac, the file Main$2.class contains the string
"hello world", 
having compiled the file in Eclipse, none of the classfiles contain the string
"hello world".
Comment 2 Andrew J Huff CLA 2005-06-02 11:16:29 EDT
quite clear whats going on,
JDT is trying to put both the inner class and the interface in the file
"Main$1.class"
Comment 3 Andrew J Huff CLA 2005-06-02 11:34:23 EDT
would also be nice if jdt gave a compile time error on this:

////////////////////////////////////////////
interface Main$A {void hello();}

public class Main{
  public static class A {void hello(){System.out.println("hello world");}}
  public static void main(String [] args){
	  Main.A a = new Main.A();
	  a.hello();
  }
}
////////////////////////////////////////////
like javac does, rather than giving a confusing runtime
java.lang.InstantiationError at line 6
Comment 4 Olivier Thomann CLA 2005-06-02 21:53:49 EDT
The problem comes from the fact that when we compute the anonymous name we don't
check existing top level or member types.
Comment 5 Olivier Thomann CLA 2005-06-02 21:59:32 EDT
One solution would be to compute the constant pool name through a factory for
all type bindings, not just the local type bindings.
Comment 6 Adrian Colyer CLA 2005-10-28 08:04:42 EDT
is there any schedule for fixing this in 3.2?
Thks, A.
Comment 7 Philipe Mulet CLA 2005-10-28 15:38:50 EDT
Let's try for 3.2m4.
Comment 8 Kent Johnson CLA 2007-06-13 12:27:32 EDT
*** Bug 188167 has been marked as a duplicate of this bug. ***
Comment 9 Kent Johnson CLA 2007-06-13 14:12:27 EDT
Created attachment 71215 [details]
Proposed patch

This should do the trick
Comment 10 Kent Johnson CLA 2007-09-26 11:22:34 EDT
Philippe - did u see the patch ?
Comment 11 Eclipse Genie CLA 2020-04-04 01:25:24 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. As such, we're closing this bug.

If you have further information on the current state of the bug, please add it and reopen this bug. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.