Bug 81590 - [1.5][compiler] Iteration over nested arrays is broken
Summary: [1.5][compiler] Iteration over nested arrays is broken
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: Other Linux
: P3 normal (vote)
Target Milestone: 3.1 M5   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 81911 (view as bug list)
Depends on:
Blocks:
 
Reported: 2004-12-18 11:00 EST by Michael Schuerig CLA
Modified: 2005-02-15 05:56 EST (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Schuerig CLA 2004-12-18 11:00:27 EST
With compiler compliance leve set to 5.0, in the following junit test case 
testIteratedAccess fails. 
 
 
import java.util.Arrays; 
import java.util.Iterator; 
 
import junit.framework.TestCase; 
 
 
public class NestedArrayTest extends TestCase { 
    private String[] a1; 
    private String[] a2; 
    private String[][] a; 
     
    protected void setUp() { 
        a1 = new String[] { "a", "b", "c" };  
        a2 = new String[] { "x", "y", "z" };  
        a = new String[][] { a1, a2 }; 
    } 
 
    public void testArraySize() { 
        assertEquals(2, a.length); 
    } 
     
    public void testIndexedAccess() { 
        assertEquals(a1, a[0]); 
        assertEquals(a2, a[1]); 
    } 
     
    public void testIteratedAccess() { 
        Iterator iter = Arrays.asList(a).iterator(); 
        assertTrue(iter.hasNext()); 
        assertEquals(a1, iter.next()); 
        assertTrue(iter.hasNext()); 
        assertEquals(a2, iter.next()); 
        assertFalse(iter.hasNext()); 
    } 
}
Comment 1 Sven Köhler CLA 2004-12-18 11:56:48 EST
smaller test-case:

String[][] x = {{"X"}, {"Y"}};
List l = Arrays.asList(x);
System.out.println(l.size() + " " + l.get(0).getClass().getName());

Compliance Level 1.4:
2 [Ljava.lang.String;

Compliance Level 5.0:
1 [[Ljava.lang.String;
Comment 2 Philipe Mulet CLA 2005-01-14 09:51:10 EST
Problem comes from varargs support which induces one extra array wrappering for
'x' in Arrays.asList(x) invocation.
Comment 3 Philipe Mulet CLA 2005-01-14 11:42:37 EST
*** Bug 81911 has been marked as a duplicate of this bug. ***
Comment 4 Philipe Mulet CLA 2005-01-14 11:43:38 EST
Tuned method type inference near varargs support.
Added VarargsTest#test018-test020.

Fixed
Comment 5 Hosam CLA 2005-01-14 15:59:07 EST
I have an existing project that includes code suffering from this bug. Is there
a way to make it compile in Eclipse M4? I can't wait for M5.
Comment 6 Philipe Mulet CLA 2005-01-14 16:30:17 EST
You could wait for next nightly build, and copy plugin org.eclipse.jdt.core back
into a M4 install. 
Comment 7 Jerome Lanneluc CLA 2005-02-15 05:56:36 EST
Verified in I20050214