diff --git a/CHANGELOG.md b/CHANGELOG.md index be211f5f..c7fba1c2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ A preview of the next release can be installed from [Babashka](https://github.com/babashka/babashka): Native, fast starting Clojure interpreter for scripting +## Unreleased +- [#1785](https://github.com/babashka/babashka/issues/1785): Allow subclasses of `Throwable` to have instance methods invoked ([@bobisageek](https://github.com/bobisageek)) + ## 1.12.196 (2024-12-24) - [#1771](https://github.com/babashka/babashka/issues/1771): `*e*` in REPL should contain exception thrown by user, not a wrapped one diff --git a/src/babashka/impl/classes.clj b/src/babashka/impl/classes.clj index 3a77e854..1f3d39dd 100644 --- a/src/babashka/impl/classes.clj +++ b/src/babashka/impl/classes.clj @@ -802,6 +802,8 @@ java.io.Closeable (instance? java.util.Collection v) java.util.Collection + (instance? java.lang.Throwable v) + java.lang.Throwable ;; keep commas for merge friendliness )] ;; (prn :res res) diff --git a/test/babashka/interop_test.clj b/test/babashka/interop_test.clj index 7dd0cf85..2aaddab5 100644 --- a/test/babashka/interop_test.clj +++ b/test/babashka/interop_test.clj @@ -223,3 +223,17 @@ UserDefinedFileAttributeView ^"[Ljava.nio.file.LinkOption;" (into-array LinkOption [])))))))) + +;; exercise a sampling of the superclass resolutions from the :public-class fn in +;; babashka.impl.classes/gen-class-map +(deftest public-class-resolutions + (testing "Charset" + (is (= "UTF-8" (bb nil "(.displayName (java.nio.charset.Charset/forName \"UTF-8\"))")))) + (testing "InputStream" + (is (zero? (bb nil "(with-open [is (java.io.InputStream/nullInputStream)] + (.available is))")))) + (testing "Throwable" + ; compare output from ex-message to calling .getMessage + (let [return-throwable "(try (yaml/parse-string \"abc: def: ghi\") (catch Exception e e))"] + (is (= (bb nil (str "(ex-message " return-throwable ")")) + (bb nil (str "(.getMessage " return-throwable ")")))))))