Community
Participate
Working Groups
The following code executes differently depending on whether it is compiled using the Eclipse compiler (3.1 RC1), or Sun's javac. public class TooManyTimes { public static void main(String[] args) { new InnerClass().start(); } public static class InnerClass { public Object start() { System.err.println("So long!"); try { return null; } finally { System.err.println("And thanks for all the fish!"); foo(); } } private void foo() { throw new IllegalStateException("Gah!"); } } } The output generated when compiled with eclipse is: So long! And thanks for all the fish! And thanks for all the fish! Exception in thread "main" java.lang.IllegalStateException: Gah! at TooManyTimes$InnerClass.foo(TooManyTimes.java:19) at TooManyTimes$InnerClass.start(TooManyTimes.java:14) at TooManyTimes.main(TooManyTimes.java:4) The output when compiled with javac is: So long! And thanks for all the fish! Exception in thread "main" java.lang.IllegalStateException: Gah! at TooManyTimes$InnerClass.foo(TooManyTimes.java:19) at TooManyTimes$InnerClass.start(TooManyTimes.java:14) at TooManyTimes.main(TooManyTimes.java:4) The difference is that "And thanks for all the fish!" is printed twice for the eclipse compiled version :-) The finally clause is executed twice!!!
Oops ! Thanks for finding this.
This only occurs when performing JSR inline (like in compliant 1.5 mode).
Problem comes from an exception attribute range which comprises the inlined finally block, thus in case of exception, it gets trapped and activates the any exception handler (second invocation of the finally block).
Added TryStatementTest#test027-028. Fixed by exit/entering subroutine code when performing inlining of finally block at exit locations in code. Fixed
Thanks Philippe! Good work :-)
Output is now: So long! And thanks for all the fish! Exception in thread "main" java.lang.IllegalStateException: Gah! at TooManyTimes$InnerClass.foo(TooManyTimes.java:19) at TooManyTimes$InnerClass.start(TooManyTimes.java:14) at TooManyTimes.main(TooManyTimes.java:4) Verified with N20050609-0010 + JDT/Core HEAD
Verified for 3.1 RC2 using build I20050610-0010