Bug 317012 - [1.6][compiler] Sun javac compiles code ok but Eclipse fails with error
Summary: [1.6][compiler] Sun javac compiles code ok but Eclipse fails with error
Status: VERIFIED DUPLICATE of bug 289247
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.7   Edit
Hardware: Macintosh Mac OS X - Carbon (unsup.)
: P3 normal (vote)
Target Milestone: 3.6 M2   Edit
Assignee: Srikanth Sankaran CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-06-16 04:22 EDT by Victort Kirst CLA
Modified: 2010-08-05 01:18 EDT (History)
3 users (show)

See Also:


Attachments
Demonstrates the bug (1.50 KB, application/x-compressed-tar)
2010-06-16 04:24 EDT, Victort Kirst CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
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