nifkuza / gwtquery

Automatically exported from code.google.com/p/gwtquery
MIT License
0 stars 0 forks source link

Eclipse 4.2 reports "method f(Object[]) is ambiguous for the type Function" errors #143

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Download latest gwtquery code from SVN and load it into an Eclipse project
2. Let eclipse try to build the project

What is the expected output? What do you see instead?
Expected output is no Java errors. Instead, Eclipse reports "The method 
f(Object[]) is ambiguous for the type Function" on lines 460, 469, and 478 of 
gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java.

What version of the product are you using? On what operating system?
SVN revision 1036, Ubuntu Linux 10.04.4 LTS (kernel 2.6.32) x86_64, Eclipse 4.2 
(Juno)

Please provide any additional information below.

The problem began after upgrading from Eclipse 3.7 to 4.2. Bug reports of a 
similar nature appear for Eclipse 3.8 and 4.2:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=383780
https://bugs.eclipse.org/bugs/show_bug.cgi?id=382469

Eclipse 4.2 (and apparently 3.8, based on comments on the bug reports linked 
above) introduced a change to mark certain ambiguous function calls as errors. 
The fact that these were not considered errors previously was due to a bug in 
JDK5 and JDK6 which has since been corrected in JDK7 and JDK8. The function 
calls in the GQuery.java code are in fact ambiguous when the Java compiler 
follows its normal rules with autoboxing.

Here are the offending lines of GQuery.java:
460: f.f(i, objects.getObject(i));
469: f.f(i, objects.get(i));
478: f.f(i, objects[i]);

In each case, i is an int. The ambiguity comes from two similar function 
definitions in Function.java:
180: public void f(Object... data)
187: public void f(int i, Object... data)

The autoboxing rules lead the Java compiler to consider (int, Object) as 
(Integer, Object), which could potentially be used to call the f(Object... 
data) function.

It appears that the Eclipse developers are working on a patch to reduce this to 
a warning or ignore it completely when building with Compiler compliance level 
1.6 or lower, but I think it would be a good idea to fix the ambiguity in the 
code rather than relying on a bug in the older JDKs.

Original issue reported on code.google.com by ty...@thamtech.com on 4 Jul 2012 at 9:54

GoogleCodeExporter commented 9 years ago
I've attached a diff with a potential solution. I'm not sure if this is a good 
proper fix, but it seems to make Eclipse happier.

Original comment by ty...@thamtech.com on 4 Jul 2012 at 11:44

Attachments:

GoogleCodeExporter commented 9 years ago

Original comment by manuel.carrasco.m on 7 Sep 2012 at 5:00

GoogleCodeExporter commented 9 years ago
This issue was closed by revision r1070.

Original comment by manuel.carrasco.m on 13 Sep 2012 at 12:16

GoogleCodeExporter commented 9 years ago
Last snapshot should work fine.

Thanks for contributing.
- Manolo

Original comment by manuel.carrasco.m on 13 Sep 2012 at 12:19

GoogleCodeExporter commented 9 years ago

Original comment by manuel.carrasco.m on 10 Dec 2012 at 7:55