Bug 321414

Summary: Synthetic constructors can exceed 255 parameters -> ClassFormatError
Product: [Eclipse Project] JDT Reporter: Matt McCutchen <hashproduct+eclipse>
Component: CoreAssignee: Olivier Thomann <Olivier_Thomann>
Status: VERIFIED FIXED QA Contact:
Severity: trivial    
Priority: P3 CC: Olivier_Thomann, satyam.kandula
Version: 3.7   
Target Milestone: 3.7 M2   
Hardware: All   
OS: All   
Whiteboard:
Attachments:
Description Flags
Test case
none
Proposed fix none

Description Matt McCutchen CLA 2010-07-30 22:30:46 EDT
Build Identifier: I20100608-0911

If one declares a private constructor with 255 parameters and accesses it from another class in the same file, Eclipse generates a synthetic constructor with 256 parameters, which is invalid and causes a ClassFormatError when the class is loaded.  This is a bug that no real user should ever encounter, so I'm marking it trivial.

For comparison, javac reports the following error, which is reasonable but doesn't give the user an explicit clue that a synthetic constructor is involved:

SyntheticConstructorTooManyArgs.java:6: too many parameters
	static class A {
	       ^
1 error

Reproducible: Always

Steps to Reproduce:
1. Compile and run the file I am about to attach.
Comment 1 Matt McCutchen CLA 2010-07-30 22:32:28 EDT
Created attachment 175636 [details]
Test case
Comment 2 Olivier Thomann CLA 2010-09-01 15:39:01 EDT
I think I have a fix for this.
We would report:
The synthetic method created to access A(int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int) of type SyntheticConstructorTooManyArgs.A has too many parameters

How does this look ?

And then a problem type is created for the corresponding class.
Comment 3 Matt McCutchen CLA 2010-09-01 22:33:25 EDT
The error message sounds good.  I'm not clear on what you are proposing with the "problem type", but it sounds like it might be overkill.  Eclipse should be able to compile all code that references A and its members except for calls to the problematic synthetic method.
Comment 4 Olivier Thomann CLA 2010-09-02 09:22:04 EDT
(In reply to comment #3)
> The error message sounds good.  I'm not clear on what you are proposing with
> the "problem type", but it sounds like it might be overkill.  Eclipse should be
> able to compile all code that references A and its members except for calls to
> the problematic synthetic method.
Yes, but when the synthetic method cannot be created because it has too many parameters, then an error is issued and inside the environment this ends up as a problem type.
A problem type is a type where each method is a problem method. So the methods exist, but they cannot be run without throwing an exception. This prevents lots of secondary errors.
Comment 5 Olivier Thomann CLA 2010-09-02 13:09:00 EDT
Created attachment 178069 [details]
Proposed fix

This should be good enough for this corner case.
Comment 6 Matt McCutchen CLA 2010-09-02 18:36:17 EDT
I will test the patch.  But why does it change "report" to "eport" in an unrelated test case?
Comment 7 Olivier Thomann CLA 2010-09-02 20:13:22 EDT
This is unrelated. When I create a test case, I end up with \r\n and I replace them with \bn.
\report was causing me grief when I did a replace all. So I removed the 'r' from report. It is just that I released both changes at the same time.
Comment 8 Olivier Thomann CLA 2010-09-07 09:40:04 EDT
Released for 3.7M2.
I reverted the confusing change in test 81.
Comment 9 Satyam Kandula CLA 2010-09-15 05:44:34 EDT
Eclipse compiler now behaves similar to the javac, but both compilers fail when the inner class is not static. For private constructors of non-static inner classes, the synthetic method takes two additional parameters. 
Filed bug 325321 to take care of it. 

As the mentioned bug is fixed, am marking this verified. 

Verified for 3.7M2 using build I20100909-1700