If you think a bug might affect users in the 57 release, please set the correct tracking and status flags for Release Management.

finally not executed if try empty

RESOLVED FIXED in 1.5R5

Status

Rhino
Compiler
RESOLVED FIXED
14 years ago
14 years ago

People

(Reporter: Mike, Assigned: Norris Boyd)

Tracking

other
1.5R5
x86
Linux

Details

Attachments

(1 attachment)

(Reporter)

Description

14 years ago
User-Agent:       Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.3b) Gecko/20021213
Build Identifier: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.3b) Gecko/20021213

(Appologies in advance if this bug was already reported.)

When there is no code in a try block, then the finally block is not executed.

Reproducible: Always

Steps to Reproduce:
try { }
finally { print(123 }


Actual Results:  
(nothing)

Expected Results:  
123

I tried this with the command line 'js', which seems to default to interprete mode.
When I do js -opt 9, I get the same results, so it looks like the compiler is
also affected.
In C's version 'SpiderMonkey' does appear to work, and does print the 123 message.

If I add a semicolon, it works:
js> try { ; } finally { print(123) }
123

Comment 1

14 years ago
Created attachment 129150 [details] [diff] [review]
Fix: optimize away empty try only if finally absent or empty

The bug is triggered by an incorrect optimization in createTryCatchFinally of
omj/IRFactory.java where it removes all try/catch/finally as long as try is
empty. 

The patch changes that to apply optimization only if finally is empty as well. 


In principle the case of empty try with a non-trivial finally can be replaced
by just the finally block instead of generating full code for try/catch/finally
support but IMO it does not that frequent to bother.

Comment 2

14 years ago
I committed the fix
Status: NEW → RESOLVED
Last Resolved: 14 years ago
Resolution: --- → FIXED

Comment 3

14 years ago
*** Bug 217591 has been marked as a duplicate of this bug. ***

Comment 4

14 years ago
Trageting as resolved against 1.5R5
Target Milestone: --- → 1.5R5
You need to log in before you can comment on or make changes to this bug.