Bug 80605 - [1.5][Generics] VerifyError exception is thrown when generics are used in ternary operator
Summary: [1.5][Generics] VerifyError exception is thrown when generics are used in ter...
Status: RESOLVED DUPLICATE of bug 78008
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 normal with 1 vote (vote)
Target Milestone: 3.1 M4   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-12-09 11:09 EST by Vladimir Khvostov CLA
Modified: 2004-12-09 15:31 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Vladimir Khvostov CLA 2004-12-09 11:09:52 EST
A VerifyError exception is thrown when next code is executed:

import java.util.ArrayList;
import java.util.List;

public class test
{
    public static void main(String[] args)
    {
        class X
        {
            private X[] EMPTY = new X[0];

            public X[] foo()
            {
                List<X> list = new ArrayList<X>();
                return list.size() == 0 ? EMPTY 
                                        : list.toArray(new X[list.size()]); 
            }
        };
        
        X x = new X();
    }
}

To workaround the problem, it is necessary to add (X[]) cast:
  return list.size() == 0 ? EMPTY : (X[])list.toArray(new X[list.size()]); 

Please note, that this only happens when the code is compiled within Eclipse. 
When the code is compiled by javac.exe from JDK 1.5 it does work correctly.
Comment 1 Vladimir Khvostov CLA 2004-12-09 11:15:25 EST
I am using 3.1.0 M3. 
Build id: 200411050810
Comment 2 Olivier Thomann CLA 2004-12-09 11:49:22 EST

*** This bug has been marked as a duplicate of 78008 ***