Fix #1785: allow subclasses of Throwable to have instance methods called via interop (#1786)

This commit is contained in:
Bob 2025-01-01 13:36:28 -05:00 committed by GitHub
parent d8521888cc
commit 3cddc33334
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 19 additions and 0 deletions

View file

@ -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

View file

@ -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)

View file

@ -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 ")")))))))