Summary: | [1.5][compiler] java.lang.VerifyError on shortcut if-else | ||||||
---|---|---|---|---|---|---|---|
Product: | [Eclipse Project] JDT | Reporter: | Jens Elkner <elkner> | ||||
Component: | Core | Assignee: | Philipe Mulet <philippe_mulet> | ||||
Status: | VERIFIED FIXED | QA Contact: | |||||
Severity: | normal | ||||||
Priority: | P3 | CC: | vladimir.khvostov | ||||
Version: | 3.1 | ||||||
Target Milestone: | 3.1 M4 | ||||||
Hardware: | PC | ||||||
OS: | Linux | ||||||
Whiteboard: | |||||||
Attachments: |
|
Description
Jens Elkner
2004-11-05 20:42:07 EST
We miss a checkcast after the toArray() call. We generate: 29 invokeinterface [nargs : 2] #30 <Interface method java/util/List.toArray([Ljava/lang/Object;)[Ljava/lang/Object;> 34 areturn instead of: 29 invokeinterface [nargs : 2] #6 <Interface method java/util/List.toArray([Ljava/lang/Object;)[Ljava/lang/Object;> 34 checkcast #7 [Ljava/lang/Integer; 37 areturn java.util.List.toArray(...) signature is: <T> T[] toArray(T[] a) So we should implicitely generate a cast to T[]. Created attachment 15711 [details]
Apply on HEAD
This is a case where we optimized the implicit conversion of the false part.
Doing this we didn't set the genericCast field and therefore there is no cast
generated after the invokeinterface.
A workaround is to reverse the condition. return list != null ? list.toArray(new Integer[list.size()]) : new Integer[0] ; works fine without the patch. Patch looks good. We are also missing #computeConversion calls further down in case: if (scope.environment().options.sourceLevel >= ClassFileConstants.JDK1_5) { Added regression test: GenericTypeTest#test408. Fixed Also added #test409 for other case mentionned in previous comment, corresponding to scenario: import java.util.*; public class X { public Number getTypes() { List<Integer> list = new ArrayList<Integer>(); return list == null ? Float.valueOf(0) : list.get(0); } public static void main(String[] args) { Class clazz = null; try { clazz = Class.forName("X"); } catch (Throwable e) { e.printStackTrace(); } } } *** Bug 80605 has been marked as a duplicate of this bug. *** Verified in 200412140800 |