Bug 82432 - [1.5] VerifyError with Autoboxing
Summary: [1.5] VerifyError with Autoboxing
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 critical (vote)
Target Milestone: 3.1 M5   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-01-08 19:17 EST by Stefan Matthias Aust CLA
Modified: 2005-02-15 05:39 EST (History)
0 users

See Also:


Attachments
Apply on HEAD (1.26 KB, patch)
2005-01-09 15:16 EST, Olivier Thomann CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
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