From 3213e8f6ba581c28211a746026b1d4655a7198ce Mon Sep 17 00:00:00 2001 From: Nicola Mometto Date: Wed, 8 Nov 2023 11:19:48 +0000 Subject: [PATCH] TRDR-71: source-logging-push-back-reader throws StringIndexOutOfBoundsException reading multiline form --- src/main/clojure/clojure/tools/reader.clj | 10 ++++++---- src/main/clojure/clojure/tools/reader/reader_types.clj | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/main/clojure/clojure/tools/reader.clj b/src/main/clojure/clojure/tools/reader.clj index 2a23011..3d32d67 100644 --- a/src/main/clojure/clojure/tools/reader.clj +++ b/src/main/clojure/clojure/tools/reader.clj @@ -1022,10 +1022,12 @@ ([] (read+string (source-logging-push-back-reader *in*))) ([stream] (read+string stream true nil)) ([^SourceLoggingPushbackReader stream eof-error? eof-value] - (let [o (log-source stream (read stream eof-error? eof-value)) - s (.trim (str (:buffer @(.source-log-frames stream))))] + (let [^StringBuilder buf (doto (:buffer @(.source-log-frames stream)) (.setLength 0)) + o (log-source stream (read stream eof-error? eof-value)) + s (.trim (str buf))] [o s])) ([opts ^SourceLoggingPushbackReader stream] - (let [o (log-source stream (read opts stream)) - s (.trim (str (:buffer @(.source-log-frames stream))))] + (let [^StringBuilder buf (doto (:buffer @(.source-log-frames stream)) (.setLength 0)) + o (log-source stream (read opts stream)) + s (.trim (str buf))] [o s]))) diff --git a/src/main/clojure/clojure/tools/reader/reader_types.clj b/src/main/clojure/clojure/tools/reader/reader_types.clj index 62239a9..06141bd 100644 --- a/src/main/clojure/clojure/tools/reader/reader_types.clj +++ b/src/main/clojure/clojure/tools/reader/reader_types.clj @@ -317,7 +317,7 @@ [reader f] (let [frame (.source-log-frames ^SourceLoggingPushbackReader reader) ^StringBuilder buffer (:buffer @frame) - new-frame (assoc-in @frame [:offset] (.length buffer))] + new-frame (assoc @frame :offset (.length buffer))] (with-bindings {frame new-frame} (let [ret (f)] (if (instance? clojure.lang.IObj ret)