From 95736f209f80adaba89c9735c9ee82d812bb9893 Mon Sep 17 00:00:00 2001 From: tuor713 Date: Sat, 5 May 2012 14:57:32 +0100 Subject: [PATCH] fix proxy-super handling of exceptions --- src/clj/clojure/core_proxy.clj | 8 ++++---- test/clojure/test_clojure/java_interop.clj | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/clj/clojure/core_proxy.clj b/src/clj/clojure/core_proxy.clj index 830f5ce..ac09207 100644 --- a/src/clj/clojure/core_proxy.clj +++ b/src/clj/clojure/core_proxy.clj @@ -357,10 +357,10 @@ (defn proxy-call-with-super [call this meth] (let [m (proxy-mappings this)] - (update-proxy this (assoc m meth nil)) - (let [ret (call)] - (update-proxy this m) - ret))) + (update-proxy this (assoc m meth nil)) + (try (call) + (finally + (update-proxy this m))))) (defmacro proxy-super "Use to call a superclass method in the body of a proxy method. diff --git a/test/clojure/test_clojure/java_interop.clj b/test/clojure/test_clojure/java_interop.clj index 55ab50f..a7ddab1 100644 --- a/test/clojure/test_clojure/java_interop.clj +++ b/test/clojure/test_clojure/java_interop.clj @@ -143,6 +143,20 @@ str) "chain chain chain"))) +(deftest test-proxy-super + (testing "proxy-super restores bindings" + (let [obj (proxy [java.lang.ClassLoader] [] + (loadClass [cl] + (try + (proxy-super loadClass cl) + (catch Exception e nil))))] + ;; sanity check + (is (= java.lang.String (.loadClass obj "java.lang.String"))) + + ;; both calls should behave the same + (is (nil? (.loadClass obj "does.not.exist"))) + (is (nil? (.loadClass obj "does.not.exist")))))) + (deftest test-bases (are [x y] (= x y) -- 1.7.0.6