Bug 82432

Summary: [1.5] VerifyError with Autoboxing
Product: [Eclipse Project] JDT Reporter: Stefan Matthias Aust <sma>
Component: CoreAssignee: Philipe Mulet <philippe_mulet>
Status: VERIFIED FIXED QA Contact:
Severity: critical    
Priority: P3    
Version: 3.1   
Target Milestone: 3.1 M5   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
Apply on HEAD none

Description Stefan Matthias Aust CLA 2005-01-08 19:17:26 EST
Exception:

java.lang.VerifyError: (class: A, method: e signature: ()Ljava/lang/Object;)
Wrong return type in function

Testcase:

public class A {
 Object e() {
  return "".compareTo("") > 0;
 }
 public static void main(String[] args) {
  System.out.println(new A().e());
 }
}

Bytecode:

java.lang.Object e();
  Code:
   0:   ldc     #17; //String
   2:   ldc     #17; //String
   4:   invokevirtual   #23; //Method
java/lang/String.compareTo:(Ljava/lang/String;)I
   7:   ifle    12
   10:  iconst_1
   11:  ireturn
   12:  iconst_0
   13:  invokestatic    #29; //Method
java/lang/Boolean.valueOf:(Z)Ljava/lang/Boolean;
   16:  areturn

The "ireturn" at position 11 is obviously wrong. A "goto 13" should be created
(as javac does).  A workaround is to help the compiler by using a redundant cast:

 return (Boolean) (... > 0);
Comment 1 Olivier Thomann CLA 2005-01-09 14:21:54 EST
The ireturn is fine as long as the implicit conversion is generated. Doing this,
the ireturn would be replaced with:

invokestatic    #29; //Method java/lang/Boolean.valueOf:(Z)Ljava/lang/Boolean;
areturn
Comment 2 Olivier Thomann CLA 2005-01-09 15:16:43 EST
Created attachment 17018 [details]
Apply on HEAD

Regression test in AutoBoxingTest.
Comment 3 Philipe Mulet CLA 2005-01-10 06:27:51 EST
The 'ireturn' bytecode is wrong; it should indeed to the boxing in this situation.
Problem comes from the bytecode optimization for 'ReturnTypeIDMASK' which isn't
properly handling boxing situations.

Comment 4 Philipe Mulet CLA 2005-01-10 06:31:18 EST
Offending bytecode optimization is actually: 'ValueForReturnMASK'.
Comment 5 Philipe Mulet CLA 2005-01-10 07:20:33 EST
Fixed in latest.
Added regression tests: AutoboxingTest#test074-077
Comment 6 Jerome Lanneluc CLA 2005-02-15 05:39:03 EST
Verified in I20050214