Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 417288

Summary: Compilation error from mismatching generic return type
Product: [Eclipse Project] JDT Reporter: Sterling Greene <sterling.greene>
Component: CoreAssignee: Stephan Herrmann <stephan.herrmann>
Status: CLOSED WONTFIX QA Contact:
Severity: normal    
Priority: P3 CC: srikanth_sankaran
Version: 3.7.2   
Target Milestone: ---   
Hardware: Other   
OS: Linux   
Whiteboard: stalebug
Attachments:
Description Flags
main.java source for the problem (same as github) none

Description Sterling Greene CLA 2013-09-15 16:36:51 EDT
Created attachment 235495 [details]
main.java source for the problem (same as github)

I've created a standalone project with just the parts that do not compile for me.  There seems to be some confusion between the two "method" methods, one takes only varargs (Object...) and the other takes a Class and varargs (Class, Object...)

https://github.com/big-guy/generic-method-bug/blob/master/src/main/java/main.java

The error is:
----------
1. ERROR in generic-method-bug/src/main/java/main.java (at line 18)
        list.addAll(method(type, thingThing));
             ^^^^^^
The method addAll(Collection<? extends T>) in the type List<T> is not applicable for the arguments (List<Object>)
----------
1 problem (1 error)

Eclipse suggests changing the return type of method(Class, Object...) to Collection<? extends T>, but that only changes the error's argument type from List<Object> to (List<capture#3-of ? extends Object>).  Ctrl+clicking the method  name on line 18 takes me to the correct method, but the mouseover shows the signature <Object> List<Object> method(Class<Object>, Object...)

I can workaround the issue by using a local variable or casting the first argument to Class.  Casting to Class<T> causes the problem to return.  Oddly enough, if I change the name of method(Object...), the problem also goes away.

I've reproduced this problem with the batch compiler in 3.7.2, 4.3, 4.3.1rc3 and 4.4-m1.   My variations compile with Sun JDK 1.5.0_22 and OpenJDK 1.7.0_25.

The actual class is (flattenToList methods):
https://github.com/gradle/gradle/blob/master/subprojects/base-services/src/main/java/org/gradle/util/CollectionUtils.java

I'm not sure if this is the same issue:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=415734
Comment 1 Srikanth Sankaran CLA 2013-09-16 00:37:08 EDT
Thanks for taking a look.
Comment 2 Eclipse Genie CLA 2020-03-10 12:37:40 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.
Comment 3 Stephan Herrmann CLA 2020-03-10 13:15:27 EDT
The problem no longer exists at compliance 1.8 or greater.