Clojure

code in finally clauses is sometimes run twice

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Resolution: Completed
  • Affects Version/s: None
  • Fix Version/s: Release 1.2
  • Component/s: None
  • Labels:
    None
  • Approval:
    Ok

Description

When an exception is thrown in a finally clause, the code inside that finally clause is run twice:

(try (prn 1) (finally (prn 2) (prn 3) (throw (Exception.))))

That prints 1 2 3 2 3, when it should simply print 1 2 3. This has been the case since revision:5e9f2b293b307aa7953cd390360d24549e542b92

But simply reverting that commit causes problems in other cases, such as:

(try (prn 1) (throw (Exception. "one"))
(catch Exception e (throw (Exception. "two")))
(finally (prn 2) (prn 3)))

...which should print 1 2 3 as well, but used to print just 1 instead.

This was discussed in http://groups.google.com/group/clojure/browse_thread/thread/43d2dcb2505e8915

Activity

Hide
Assembla Importer added a comment -
Show
Assembla Importer added a comment - Converted from http://www.assembla.com/spaces/clojure/tickets/422 Attachments: 0001-Emit-finally-exception-table-entry-for-each-try-catc.patch - https://www.assembla.com/spaces/clojure/documents/d9le_6Pvar35I1eJe5cbLr/download/d9le_6Pvar35I1eJe5cbLr
Hide
Assembla Importer added a comment -

chouser@n01se.net said: [file:d9le_6Pvar35I1eJe5cbLr]: initial fix for #422

Show
Assembla Importer added a comment - chouser@n01se.net said: [file:d9le_6Pvar35I1eJe5cbLr]: initial fix for #422
Hide
Assembla Importer added a comment -

chouser@n01se.net said: It looks like javac protects the try block and each catch block individually with separate entries in the exception table, all of them pointing to the final finally block.

This patch attempts to do the same thing, and also fully reverses the "endTryCatch" commit mentioned in the ticket description. Both the examples in the ticket description work correctly, each printing just 1 2 3.

Show
Assembla Importer added a comment - chouser@n01se.net said: It looks like javac protects the try block and each catch block individually with separate entries in the exception table, all of them pointing to the final finally block. This patch attempts to do the same thing, and also fully reverses the "endTryCatch" commit mentioned in the ticket description. Both the examples in the ticket description work correctly, each printing just 1 2 3.
Hide
Assembla Importer added a comment -

richhickey said: Thanks!

This could use some tests

Show
Assembla Importer added a comment - richhickey said: Thanks! This could use some tests
Hide
Assembla Importer added a comment -

chouser@n01se.net said: Joe Gallo wrote some. He said his CA is in the mail.

Show
Assembla Importer added a comment - chouser@n01se.net said: Joe Gallo wrote some. He said his CA is in the mail.
Hide
Assembla Importer added a comment -

richhickey said: Where are they? We can try them without including them for now

Show
Assembla Importer added a comment - richhickey said: Where are they? We can try them without including them for now
Hide
Assembla Importer added a comment -

chouser@n01se.net said: They were linked from the ggroup discussion. They pass.

http://gist.github.com/517871

Show
Assembla Importer added a comment - chouser@n01se.net said: They were linked from the ggroup discussion. They pass. http://gist.github.com/517871
Hide
Assembla Importer added a comment -

richhickey said: Thanks, I missed that, I was looking for them in messages from Joe

Show
Assembla Importer added a comment - richhickey said: Thanks, I missed that, I was looking for them in messages from Joe
Hide
Assembla Importer added a comment -

stu said: Updating tickets (#404, #422, #382, #423)

Show
Assembla Importer added a comment - stu said: Updating tickets (#404, #422, #382, #423)
Hide
Assembla Importer added a comment -

chouser@n01se.net said: (In [[r:5d4022276177d562906700c428f544110a0d0f1f]]) Emit finally exception table entry for each try/catch clause. Refs #422

Signed-off-by: Stuart Halloway <stu@thinkrelevance.com>

Branch: master

Show
Assembla Importer added a comment - chouser@n01se.net said: (In [[r:5d4022276177d562906700c428f544110a0d0f1f]]) Emit finally exception table entry for each try/catch clause. Refs #422 Signed-off-by: Stuart Halloway <stu@thinkrelevance.com> Branch: master

People

  • Assignee:
    Chouser
    Reporter:
    Anonymous
Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: