Bug 239305 - [compiler] VerifyError caused by casting long to long to int
Summary: [compiler] VerifyError caused by casting long to long to int
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.4   Edit
Hardware: Macintosh Mac OS X - Carbon (unsup.)
: P3 normal (vote)
Target Milestone: 3.4.1   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 239594 (view as bug list)
Depends on:
Blocks:
 
Reported: 2008-07-02 14:37 EDT by Joel Dyck CLA
Modified: 2008-08-28 15:57 EDT (History)
5 users (show)

See Also:


Attachments
Sample project (3.64 KB, application/zip)
2008-07-02 14:37 EDT, Joel Dyck CLA
no flags Details
Proposed patch (3.79 KB, patch)
2008-07-03 18:27 EDT, Philipe Mulet CLA
no flags Details | Diff
Better patch (4.52 KB, patch)
2008-07-04 06:04 EDT, Philipe Mulet CLA
no flags Details | Diff
Patch for 3.4.x (2.21 KB, patch)
2008-07-04 06:04 EDT, Philipe Mulet CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Joel Dyck CLA 2008-07-02 14:37:56 EDT
Created attachment 106339 [details]
Sample project

Build ID: I20080617-2000

Steps To Reproduce:
1. Import attached sample project
2. Debug or Run the project through Eclipse, get VerifyError
3. Compile and run from command line, no error


More information:
Problem found when running on Mac OS X Leopard (10.5.4)
Java version: 
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_13-b05-237)
Java HotSpot(TM) Client VM (build 1.5.0_13-119, mixed mode, sharing)


The code compiles in Eclipse, but when run or debugged gives the error:
Exception in thread "main" java.lang.VerifyError: (class: CastingVerifyError, method: castLongToInt signature: (J)I) Expecting to find long on stack

When compiled with javac and run from command line, no error occurs

The code also compiled and ran without errors in Eclipse 3.3
Comment 1 Darin Wright CLA 2008-07-02 14:59:45 EDT
This works for me on XP and Mac OS 10.5.3 (using the same VM as shown below).
Comment 2 Joel Dyck CLA 2008-07-02 15:36:14 EDT
Decompiling the .class files (javap -private -c CastingVerifyError) gives the following:

.class file created by Eclipse compiler (error case):
Compiled from "CastingVerifyError.java"
public class CastingVerifyError extends java.lang.Object{
public CastingVerifyError();
  Code:
   0:	aload_0
   1:	invokespecial	#8; //Method java/lang/Object."<init>":()V
   4:	return

public static void main(java.lang.String[]);
  Code:
   0:	return

private static int castLongToInt(long);
  Code:
   0:	lload_0
   1:	l2i
   2:	l2i
   3:	ireturn

}



.class file created by default javac command line (working case):
Compiled from "CastingVerifyError.java"
public class CastingVerifyError extends java.lang.Object{
public CastingVerifyError();
  Code:
   0:	aload_0
   1:	invokespecial	#1; //Method java/lang/Object."<init>":()V
   4:	return

public static void main(java.lang.String[]);
  Code:
   0:	return

private static int castLongToInt(long);
  Code:
   0:	lload_0
   1:	l2i
   2:	ireturn

}

Comment 3 Darin Wright CLA 2008-07-02 16:10:36 EDT
Moving to JCORE for comment.
Comment 4 Philipe Mulet CLA 2008-07-03 06:39:04 EDT
Reproduced in latest.
Comment 5 Philipe Mulet CLA 2008-07-03 06:53:36 EDT
Only occurs if enabling the diagnosis for unnecessary cast (-warn:+uselessTypeCheck)
Comment 6 Philipe Mulet CLA 2008-07-03 06:55:06 EDT
Regression over 3.3.2, introduced during 3.4M7
Comment 7 Philipe Mulet CLA 2008-07-03 18:25:12 EDT
Problem comes from a side-effect on implicitConversion performed by alternate cast check (as part of diagnosis for unused cast).
Comment 8 Philipe Mulet CLA 2008-07-03 18:25:46 EDT
Workaround is to disable the optional warning for unnecessary cast.
Comment 9 Philipe Mulet CLA 2008-07-03 18:26:08 EDT
Added CastTest#test045
Comment 10 Philipe Mulet CLA 2008-07-03 18:27:27 EDT
Created attachment 106523 [details]
Proposed patch
Comment 11 Philipe Mulet CLA 2008-07-04 06:04:13 EDT
Created attachment 106564 [details]
Better patch
Comment 12 Philipe Mulet CLA 2008-07-04 06:04:38 EDT
Created attachment 106565 [details]
Patch for 3.4.x
Comment 13 Philipe Mulet CLA 2008-07-04 06:05:09 EDT
Released for 3.4.1
Comment 14 Philipe Mulet CLA 2008-07-04 06:07:03 EDT
Released for 3.5M1.
Fixed
Comment 15 Philipe Mulet CLA 2008-07-04 08:40:47 EDT
*** Bug 239594 has been marked as a duplicate of this bug. ***
Comment 16 Philipe Mulet CLA 2008-07-04 08:42:28 EDT
Re: comment 8.
BTW a better workaround is simply to remove the unnecessary cast (to long in this case).
Comment 17 Olivier Thomann CLA 2008-08-06 14:33:23 EDT
Verified for 3.5M1 using I20080805-1307
Comment 18 Jerome Lanneluc CLA 2008-08-28 15:57:24 EDT
Verified for 3.4.1 using M20080827-2000