are you using any IDE? mine is (win 2k): java version "1.4.1_02" Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_02-b06) Java HotSpot(TM) Client VM (build 1.4.1_02-b06, mixed mode) [ August 22, 2003: Message edited by: Andres Gonzalez ]
I'm not going to be a Rock Star. I'm going to be a LEGEND! --Freddie Mercury
No problem here. Compiles and prints 0 as expected. Powerbook G4 Titanium, Mac OS 10.2.6 java version "1.4.1_01" Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_01-39) Java HotSpot(TM) Client VM (build 1.4.1_01-14, mixed mode) ---BW
http://developer.java.sun.com/developer/bugParade/bugs/4842426.html Bug Id 4842426 Votes 1 Synopsis RFE: try-catch-finally compiler message request Category java:compiler Reported Against 1.4.1 Release Fixed State Closed, duplicate of 4814715 Related Bugs Submit Date Apr 03, 2003 A DESCRIPTION OF THE REQUEST : java version "1.4.1_01" Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_01-b01) Java HotSpot(TM) Client VM (build 1.4.1_01-b01, mixed mode) If a try block has a return statement and a finally block is added with a return statement, the first return statement is ignored/unused. JUSTIFICATION : The compiler should warn or error and tell coders that the first return statement is unreachable.
Thanks Marlene. But I think the right link that properly describes my problem is this one. Actually, looking at the original link, I don't know why they complained about this as a problem:
If a try block has a return statement and a finally block is added with a return statement, the first return statement is ignored/unused.
The problem described in the bug report IS the expected behaviour, as written in the book The Java Programming Language 3rd Edition pp 206 by Arnold, Gosling and Holmes:
A finally clause is always entered with a reason. That reason may be that the try code finished normally, that it executed a control flow statement such as return, or that an exception was thrown in code executed in the try block. The reason is remembered when the finally clause exits by falling out the bottom. However, if the finally block creates its own reason to leave by executing a control flow statement(such as break or return) or by throwing exception, that reason supersedes the original one, and the reason is forgotten.
[ August 24, 2003: Message edited by: Alton Hernandez ]