Bug 37621

Summary: java compiler creates class with internal inconsistency
Product: [Eclipse Project] JDT Reporter: Ken Chupa <chupa>
Component: CoreAssignee: Philipe Mulet <philippe_mulet>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: eckart.langhuth, jim-aj, vlahoda
Version: 2.1   
Target Milestone: 2.1.1   
Hardware: PC   
OS: Windows 2000   
Whiteboard:
Attachments:
Description Flags
Source code for the class that gets compiled incorrectly
none
The "inconsistent" class file none

Description Ken Chupa CLA 2003-05-14 17:23:55 EDT
The class gets the following error at runtime:
java.lang.VerifyError: (class: org/spec/jappserver/ruleengine/RuleParser, 
method: TypeDeclaration signature: ()V) Illegal target of jump or branch

The test case is SPECjAppServer2002 v1.14. The ear file contains several EJB 
jar files, with interdependencies. RuleParser is in corp.jar. During the build, 
got the following msg from RMIC
[*Warning] ejbModule/org/spec/jappserver/ruleengine/RuleParser.java(1995):
The static method addDimension(int, LinkedList) from the type RuleProcessor
should be accessed in a static way
Comment 1 Ken Chupa CLA 2003-05-14 17:34:34 EDT
Created attachment 4879 [details]
Source code for the class that gets compiled incorrectly

I will also attach the class file created from this source
Comment 2 Ken Chupa CLA 2003-05-14 17:48:23 EDT
Created attachment 4880 [details]
The "inconsistent" class file

This is the class file that gets the VerifyError at runtime
Comment 3 Philipe Mulet CLA 2003-05-14 18:17:51 EDT
Which build are you using ?
Comment 4 Ken Chupa CLA 2003-05-15 12:15:24 EDT
This is occuring with driver
wswb-M20030507-200305071654
Comment 5 Philipe Mulet CLA 2003-05-16 06:20:18 EDT
I was hoping it to be a dup of bug 37040, but the timestamp looks that cannot 
be true. Will investigate.
Comment 6 Philipe Mulet CLA 2003-05-16 06:39:24 EDT
Reproduced.
Comment 7 Philipe Mulet CLA 2003-05-16 07:07:24 EDT
Working on a fix for it for 2.1.1 (not ready yet).

Problem is due to statements {if (true) throw new ParserException(...)}, which 
are fooling us into thinking we can optimize out the trailing #return bytecode, 
which is a branch target (for the break inside the switch statement).

Simpler test case:
public class X {
	
	public static void main(String[] args) {
		if (args != null) {
			if (true) throw new NullPointerException();
		} else {
			switch (args.length) {
				case 1: 
					if (true) throw new NullPointerException
();
					break;
				case 0: 
					break;
				default: 
					throw new NullPointerException();
			}
		}
	}
}
Comment 8 Philipe Mulet CLA 2003-05-16 07:46:23 EDT
Bug isolated. The flow analysis got fooled by a fake reachable 'break' 
statement which tricked it into ignoring subsequent valid break statements 
which can reach the end of the switch. Thus it thought that all subsequent 
statements behind the switch could be optimized out (in particular the implicit 
return bytecode could be thrown away).

In RuleParser, you may workaround it by changing the following lines 183-184 

    {if (true) throw new ParseException("Interface declarations not supported 
in rule!");}
        break;

into the one line below:

{throw new ParseException("Interface declarations not supported in rule!");}

Comment 9 Philipe Mulet CLA 2003-05-17 04:35:20 EDT
Fixed and released in both 2.1 maintenance and 3.0 streams.
Comment 10 David Audel CLA 2003-06-02 09:23:21 EDT
Verified.
Comment 11 Philipe Mulet CLA 2003-06-03 05:17:30 EDT
*** Bug 38345 has been marked as a duplicate of this bug. ***
Comment 12 Philipe Mulet CLA 2003-06-10 09:32:45 EDT
*** Bug 38702 has been marked as a duplicate of this bug. ***
Comment 13 David Audel CLA 2003-06-10 10:25:01 EDT
Verified for 3.0M1.
Comment 14 Philipe Mulet CLA 2003-06-17 15:10:52 EDT
*** Bug 39020 has been marked as a duplicate of this bug. ***