Bug 317012

Summary: [1.6][compiler] Sun javac compiles code ok but Eclipse fails with error
Product: [Eclipse Project] JDT Reporter: Victort Kirst <victor.kirst>
Component: CoreAssignee: Srikanth Sankaran <srikanth_sankaran>
Status: VERIFIED DUPLICATE QA Contact:
Severity: normal    
Priority: P3 CC: jarthana, satyam.kandula, srikanth_sankaran
Version: 3.7   
Target Milestone: 3.6 M2   
Hardware: Macintosh   
OS: Mac OS X - Carbon (unsup.)   
Whiteboard:
Attachments:
Description Flags
Demonstrates the bug none

Description Victort Kirst CLA 2010-06-16 04:22:45 EDT
Build Identifier: 20100610-0636

The following code compiles using Javac 1.6 but fails with Eclipse 3.6RC4:

import java.util.Arrays;
import java.util.Collection;


public class Test {

	public static void main(String[] args) {
		System.out.println(Test.asArray(Arrays.asList(1, 2, 3, 4)).getClass());
		System.out.println(Test.asArray(Arrays.asList(1l, 2l, 3l, 4l)).getClass());
	}

    public static int[] asArray(Collection<Integer> list) {
        int[] array = new int[list.size()];
        int index = 0;
        for (int element : list) {
            array[index] = element;
            index++;
        }
        return array;
    }

    public static long[] asArray(Collection<Long> list) {
        long[] array = new long[list.size()];
        int index = 0;
        for (long element : list) {
            array[index] = element;
            index++;
        }
        return array;
    }
}

Reproducible: Always

Steps to Reproduce:
1. Open attached project in Eclipse, compiles (with errors)
2.Try to compile the same classes using javac 1.6.20 on the command-line =>
Ok
Comment 1 Victort Kirst CLA 2010-06-16 04:24:00 EDT
Created attachment 172020 [details]
Demonstrates the bug
Comment 2 Srikanth Sankaran CLA 2010-06-16 05:28:22 EDT
This is a defect in the Sun/Oracle compiler.
See http://bugs.sun.com/view_bug.do?bug_id=6182950
fixed and released only in the JDK 7 stream.

Accordingly if I compile the snippet attached
to this bug using javac 7 I get:

Test.java:23: name clash: asArray(Collection<Long>) and asArray(Collection<Integ
er>) have the same erasure
    public static long[] asArray(Collection<Long> list) {
                         ^
Test.java:9: method asArray in class Test cannot be applied to given types
        System.out.println(Test.asArray(Arrays.asList(1l, 2l, 3l,
                               ^
  required: Collection<Integer>
  found: List<Long>
2 errors

*** This bug has been marked as a duplicate of bug 289247 ***
Comment 3 Victort Kirst CLA 2010-06-16 05:34:49 EDT
I see. Thank You for the fast response.
Comment 4 Satyam Kandula CLA 2010-08-05 01:18:59 EDT
Verified for 3.7M1 using build I20100802-1800