| Summary: | Strange behavior when compiling class with the same name as an anonymous class | ||
|---|---|---|---|
| Product: | [Eclipse Project] JDT | Reporter: | Kamil Jarosz <kamil09875> |
| Component: | Core | Assignee: | JDT-Core-Inbox <jdt-core-inbox> |
| Status: | CLOSED WONTFIX | QA Contact: | |
| Severity: | normal | ||
| Priority: | P3 | CC: | kamil09875, sasikanth.bharadwaj |
| Version: | 4.7.1a | ||
| Target Milestone: | --- | ||
| Hardware: | PC | ||
| OS: | Windows 10 | ||
| Whiteboard: | stalebug | ||
Reproduced on master, but can't be something new. Will investigate 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. |
For the following code: public class Bug{ public static void main(String[] args){ new Runnable(){ public void run(){ System.out.println("Anonymous"); } }.run(); Bug$1.test(); } } class Bug$1{ public static void test(){ System.out.println("Bug$1"); } } Name of the anonymous class in the main method is the same as the name of Bug$1 class. The compiler compiles them to one file: the former is replaced by the latter. When I run the code I get NoSuchMethodError: test.Bug$1.run()V or test.Bug$1.test()V, depending on the compiled class. The choice seems pretty random -- in some situations the behavior changes after renaming a method. When compiling with javac (jdk1.8.0_92, jdk-9.0.1) the anonymous class is compiled into Bug$2.class and everything works fine.