Bug 77422 - [1.5][compiler] ArrayIndexOutOfBoundsException with vararg constructor of generic superclass
Summary: [1.5][compiler] ArrayIndexOutOfBoundsException with vararg constructor of gen...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 major (vote)
Target Milestone: 3.1 M4   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 78016 78467 (view as bug list)
Depends on:
Blocks:
 
Reported: 2004-11-01 15:56 EST by Garret Wilson CLA
Modified: 2006-06-23 19:00 EDT (History)
3 users (show)

See Also:


Attachments
log entries for described error (25.00 KB, text/plain)
2004-11-01 16:37 EST, Garret Wilson CLA
no flags Details
Proposed fix (1.41 KB, patch)
2004-11-03 07:02 EST, Jerome Lanneluc CLA
no flags Details | Diff
Proposed regression test (2.20 KB, patch)
2004-11-03 07:02 EST, Jerome Lanneluc CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Garret Wilson CLA 2004-11-01 15:56:27 EST
I have:

public class MyClass extends ParentClass<AnotherClass>
{

  public MyClass(SomeClass someClass)
  {
    super(someClass, value1, value2, value3);
  }
}

Where ParentClass<T> has the following constructor:

public ParentClass(SomeClass someClass, ValueClass... values)

I get:

Internal compiler error java.lang.ArrayIndexOutOfBoundsException:
2 at
org.eclipse.jdt.internal.compiler.lookup.ParameterizedGenericMethodBinding.computeCompatibleMethod(ParameterizedGenericMethodBinding.java:98)
at
org.eclipse.jdt.internal.compiler.lookup.Scope.computerCompatibleMethod(Scope.java:231)
at
etc.

This occurs on I20041101, and has occurred for quite a while. I can't build my
project, even though it builds fine on NetBeans.

Garret
Comment 1 Olivier Thomann CLA 2004-11-01 16:30:35 EST
Could you please provide a test case and the whole .log file?
You remove part of the stack trace that we would like to see.
Comment 2 Garret Wilson CLA 2004-11-01 16:37:53 EST
Created attachment 15530 [details]
log entries for described error

I'm afraid I can't provide a test case right now, but I am attaching the
relevant log entries.
Comment 3 Olivier Thomann CLA 2004-11-01 17:55:02 EST
We can reproduce a failure in the reconciler, but we don't get the stack trace.
So a test case would really help to get it fix.
Comment 4 Olivier Thomann CLA 2004-11-02 13:09:31 EST
Likely a bug in SourceTypeConverter
Comment 5 Olivier Thomann CLA 2004-11-02 13:11:59 EST
package p;

public class MyClass extends ParentClass {

	public MyClass(Exception someClass) {
		super(someClass, "", "", "");
	}
}

package p;

public class ParentClass<T> {
	public ParentClass(T someClass, T... values) {
		System.out.println("Toto");
	}
}
Comment 6 Jerome Lanneluc CLA 2004-11-02 13:15:03 EST
Olivier says: "You won't get the crash anymore, but if you write a simple test
case you will see the red line under the method call"
Comment 7 Jerome Lanneluc CLA 2004-11-02 13:19:17 EST
To be exact, Olivier says that the calls to super(...) is underlied in red,
wheras the compiler doesn't find a problem.
Comment 8 Garret Wilson CLA 2004-11-02 15:49:10 EST
Did this get into I20041102? Let me know, and I'll test it out.
Comment 9 Olivier Thomann CLA 2004-11-02 15:51:15 EST
In I20041102, we still have a bug in the reconciler. But I cannot reproduce the
stack trace you got. It would be nice if you could give it a try and let us know.
Also it would be nice to get your test case.
Thanks.
Comment 10 Jerome Lanneluc CLA 2004-11-03 05:59:43 EST
Simpler test case:

package p;
public class ParentClass {
	public ParentClass(String... values) {
	}
}

package p;
public class MyClass extends ParentClass {
	public MyClass() {
		super("");
	}
}
Comment 11 Jerome Lanneluc CLA 2004-11-03 07:01:42 EST
SourceElementParser is not marking the constructor with AccVarargs
Comment 12 Jerome Lanneluc CLA 2004-11-03 07:02:17 EST
Created attachment 15593 [details]
Proposed fix
Comment 13 Jerome Lanneluc CLA 2004-11-03 07:02:45 EST
Created attachment 15594 [details]
Proposed regression test
Comment 14 Jerome Lanneluc CLA 2004-11-03 09:28:48 EST
Patches are against I200411022000
Comment 15 Garret Wilson CLA 2004-11-03 11:36:05 EST
FYI I still get the stack trace in I20041102 from the internal compiler error.

Note there is also an error (not an internal compiler error, but an inability to
resolve the super method) on the following line:

void foo(MyClass myClass)
{
  super.foo(myClass.getProperty(), myClass.getEnumProperty());
}

where super.foo() is defined as in an abstract base class:

protected void foo(Object... values);

and MyClass.getEnumProperty() returns a value of type MyClass.MyEnum.

Eclipse seems to be having trouble with an enum being passed to a vararg method
of an abstract base class. (I don't know if this is the ultimate source of the
internal compiler error.)

I realize that a true test case would be helpful---I'm trying to get the time to
produce one. (It's a busy week.)
Comment 16 Philipe Mulet CLA 2004-11-03 16:27:25 EST
Ok for M3
Comment 17 Jerome Lanneluc CLA 2004-11-04 05:33:26 EST
Released propoosed patch and regression test.
Comment 18 Frederic Fusier CLA 2004-11-04 10:02:29 EST
Verified for 3.1 M3 with build I200411040010 + jdt.core HEAD

I've tested test similar to comment 0:
MyClass.java:
  package q;
  import static q.ValueClass.*;

  class AnotherClass {}
  class SomeClass {}

  public class MyClass extends ParentClass<AnotherClass> {
	public MyClass(SomeClass someClass) {
		super(someClass, VALUE1, VALUE2, VALUE3);
	}
  }
ParentClass.java:
  package q;
  public class ParentClass<T> {
	public ParentClass(SomeClass someClass, ValueClass... values) {
	}
  }
ValueClass.java:
  package q;
  public enum ValueClass {
	VALUE1, VALUE2, VALUE3
  }

and it compiles without any error nor exception.
Comment 19 Garret Wilson CLA 2004-11-05 17:07:09 EST
As I mentioned earlier, this bug still shows up---on 20041104, at least.

On the positive side, I've managed to managed to produce a test case (see
below). Note that this appears to be the same bug, even though it may in the end
not have to do with accessing a generic superclass.

(I debated whether to consider this a new bug, but as my original complaint was
never fixed, I'll consider this the same bug, even if my original post allowed
you to fix some *other* bug which you found because of my post. :) )

package com.example;

import java.util.*;

public class TestClass<T>
{

	public boolean test1()
	{
			test2("test", null, 0);
	}

	public <F> List<F> test2(final List<F> list, final String... strings)
	{
		return null;
	}


}
Comment 20 Garret Wilson CLA 2004-11-05 17:23:58 EST
Um, don't want to argue, but this seems to be more severe than "normal". On the
other hand, I suppose it seems worse from my point of view because I've been
forced to use Net@#$Beans for weeks because my code won't compile on Eclipse. :)
Comment 21 Olivier Thomann CLA 2004-11-05 17:30:18 EST
This is a bug in the compiler. It doesn't handle variable arguments inside
generic method.
With a test case earlier in the week, this could probably be fixed for M3. I let
Philippe set the severity.
Compiling your test case with the batch compiler also produces the same stack trace.
Comment 22 Olivier Thomann CLA 2004-11-06 08:34:56 EST
*** Bug 78016 has been marked as a duplicate of this bug. ***
Comment 23 Philipe Mulet CLA 2004-11-08 05:06:01 EST
Problem comes from the lack of support for varargs in generic methods.
Inference mechanism naively relies on same argument and parameter count.
Comment 24 Philipe Mulet CLA 2004-11-08 06:01:52 EST
Support added. 
Added regression tests: GenericTypeTest#test387-test392
Fixed
Comment 25 Philipe Mulet CLA 2004-11-08 06:04:24 EST
In order to benefit from fix, you could take the next nightly/integration build,
and copy org.eclipse.jdt.core plugin back into 3.1M3.
Comment 26 R Lenard CLA 2004-11-09 00:02:50 EST
This is some trivial code that causes the problem.
%cat Test.java
import java.util.Arrays;
import java.util.Collection;

public class Test
{
    public static void main(String[] args)
    {
        final Collection<String> x = Arrays.asList("A", "B");
    }
}
Comment 27 Philipe Mulet CLA 2004-11-12 09:17:35 EST
*** Bug 78467 has been marked as a duplicate of this bug. ***
Comment 28 Frederic Fusier CLA 2004-11-12 13:32:52 EST
*** Bug 78467 has been marked as a duplicate of this bug. ***
Comment 29 Olivier Thomann CLA 2004-12-14 12:20:27 EST
Verified in 200412140800
Comment 30 Philipe Mulet CLA 2006-06-23 19:00:27 EDT
*** Bug 78467 has been marked as a duplicate of this bug. ***