Bug 80605

Summary: [1.5][Generics] VerifyError exception is thrown when generics are used in ternary operator
Product: [Eclipse Project] JDT Reporter: Vladimir Khvostov <vladimir.khvostov>
Component: CoreAssignee: JDT-Core-Inbox <jdt-core-inbox>
Status: RESOLVED DUPLICATE QA Contact:
Severity: normal    
Priority: P3    
Version: 3.1   
Target Milestone: 3.1 M4   
Hardware: PC   
OS: Windows XP   
Whiteboard:

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 ***