Community
Participate
Working Groups
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 ?)
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 {}
Patch posted at https://bugs.eclipse.org/bugs/show_bug.cgi?id=340022#c5 fixes this issue and has a junit also.
> 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
Verified.