Bug 289538 - [1.5][compiler] compiler fails to generate correct code for private constructor in inner class
Summary: [1.5][compiler] compiler fails to generate correct code for private construct...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.6   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.6 M3   Edit
Assignee: Kent Johnson CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-09-15 21:41 EDT by Tim Margush CLA
Modified: 2009-10-27 02:40 EDT (History)
3 users (show)

See Also:


Attachments
test case (350 bytes, application/octet-stream)
2009-09-15 21:49 EDT, Tim Margush CLA
no flags Details
Proposed patch and testcase (4.24 KB, patch)
2009-09-17 11:52 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 Tim Margush CLA 2009-09-15 21:41:14 EDT
User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3 (.NET CLR 3.5.30729)
Build Identifier: I20080617-2000

The synthesized constructor for an inner class's private constructor may match the signature of an explicit constructor causing a class load error at runtime due to a duplicate method signature. The Sun compiler correctly compiles the sample code by generating an extra anonymous class.

Reproducible: Always

Steps to Reproduce:
1. Compile sample code - no errors
2. Run - execution fails when inner class object is instantiated
3. If the single parameter constructor is changed to public, there is no error.



Error
Exception in thread "main" java.lang.ClassFormatError: Duplicate method name&signature in class file LList$Node
	at java.lang.ClassLoader.defineClass1(Native Method)
...
Comment 1 Tim Margush CLA 2009-09-15 21:49:35 EDT
Created attachment 147264 [details]
test case

I think the synthesized constructor for the private Node(T e) is Node(T e, Node x) which matches the second constructor.

javac produces 3 class files
LList
LList$1
LList$Node

eclipse generates only 2
LList
LList$Node

(The sample program produces no output, except for the error trace)
Comment 2 Stephan Herrmann CLA 2009-09-16 10:12:12 EDT
The compiler doesn't detect the collision, because it compares
a parameterized signature with a raw one.

Within method SyntheticMethodBinding.initializeConstructorAccessor(MethodBinding)
it is not OK to use areParametersEqual(MethodBinding), but
erasures must be compared.

Switching from areParametersEqual to areParameterErasuresEqual
solves this problem.
Comment 3 Kent Johnson CLA 2009-09-17 11:52:22 EDT
Created attachment 147451 [details]
Proposed patch and testcase

Thanks Stephan
Comment 4 Kent Johnson CLA 2009-09-17 13:43:08 EDT
Released to HEAD for 3.6M3
Comment 5 Srikanth Sankaran CLA 2009-10-27 02:40:02 EDT
Verified for 3.6M3 using build I20091025-2000