Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 340484

Summary: [1.7][compiler] Failure in computing precisely rethrown types.
Product: [Eclipse Project] JDT Reporter: Srikanth Sankaran <srikanth_sankaran>
Component: CoreAssignee: Srikanth Sankaran <srikanth_sankaran>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: amj87.iitr, Olivier_Thomann
Version: 3.7   
Target Milestone: 3.7.1   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Srikanth Sankaran CLA 2011-03-19 06:13:38 EDT
While reviewing the code changes done for bug 340022, I realized that
the code as it is will compile the following code alright in 1.7 source
level while it should not. Indeed javac 7b131 refuses to compile it:

public class X {
	public static void main(String[] args) {
		try {
			throw new DaughterOfFoo();
		} catch(Foo e) {
			try { 
				while (true) {
					throw e; 
				}
			} catch (SonOfFoo e1) {
			 	e1.printStackTrace();
			} catch (Foo e1) {}
		}
	}
}
class Foo extends Exception {}
class SonOfFoo extends Foo {}
class DaughterOfFoo extends Foo {}

The problem stems from the line of code:

if (argumentEffectivelyFinal == true && traversedContext instanceof ExceptionHandlingFlowContext) in flowContext.java. By inserting an
artificial while loop in the test case, the if statement is short
circuited, resulting in the incorrect behavior.

BTW, why argumentEffectivelyFinal == true ? instead of simply argumentEffectivelyFinal ? (may be better renamed argumentIsEffectivelyFinal ?)
Comment 1 Srikanth Sankaran CLA 2011-03-19 06:16:37 EDT
Another related problem:

The following code fails to compile with source level 1.6 and
compliance level 1.7. I think precise rethrow semantics should
be keyed off of (i.e trigger with) the source level and not 
compliance level.

public class X {
	public static void main(String[] args) {
		try {
			throw new DaughterOfFoo();
		} catch(Foo e) {
			try { 
					throw e; 
			} catch (SonOfFoo e1) {
			 	e1.printStackTrace();
			} catch (Foo e1) {}
		}
	}
}
class Foo extends Exception {}
class SonOfFoo extends Foo {}
class DaughterOfFoo extends Foo {}
Comment 2 Srikanth Sankaran CLA 2011-03-20 02:58:23 EDT
Patch posted at https://bugs.eclipse.org/bugs/show_bug.cgi?id=340022#c5
fixes this issue and has a junit also.
Comment 3 Srikanth Sankaran CLA 2011-03-21 05:04:13 EDT
> Patch posted at https://bugs.eclipse.org/bugs/show_bug.cgi?id=340022#c5
> fixes this issue and has a junit also.

Resolved by the patch posted at (released into BETA_JAVA7 branch)
https://bugs.eclipse.org/bugs/show_bug.cgi?id=340022#c8
Comment 4 Olivier Thomann CLA 2011-06-28 09:35:37 EDT
Verified.