Welcome! Please see the About page for a little more info on how this works.

0 votes
in tools.reader by
recategorized by

I triggered this in real code with a form like this one:

(defn ^:1234567891011 foo []

);

Sending a file with this form (cider-load-buffer in emacs) throws an exception:

StringIndexOutOfBoundsException: Range [44, 34) out of bounds for length 34
	jdk.internal.util.Preconditions$1.apply (Preconditions.java:55)
	jdk.internal.util.Preconditions$1.apply (Preconditions.java:52)
	jdk.internal.util.Preconditions$4.apply (Preconditions.java:213)
	jdk.internal.util.Preconditions$4.apply (Preconditions.java:210)
	jdk.internal.util.Preconditions.outOfBounds (Preconditions.java:98)
	jdk.internal.util.Preconditions.outOfBoundsCheckFromToIndex (Preconditions.java:112)
	jdk.internal.util.Preconditions.checkFromToIndex (Preconditions.java:349)
	java.lang.AbstractStringBuilder.substring (AbstractStringBuilder.java:1086)
	java.lang.StringBuilder.substring (StringBuilder.java:91)
	java.lang.AbstractStringBuilder.substring (AbstractStringBuilder.java:1038)
	java.lang.StringBuilder.substring (StringBuilder.java:91)
	clojure.tools.reader.reader-types/peek-source-log (reader_types.clj:248)
	clojure.tools.reader.reader-types/peek-source-log (reader_types.clj:243)
	clojure.tools.reader.reader-types/log-source*/fn--4391 (reader_types.clj:324)
	clojure.core/apply (core.clj:667)
	clojure.core/with-bindings* (core.clj:1990)
	clojure.core/with-bindings* (core.clj:1990)
	clojure.tools.reader.reader-types/log-source* (reader_types.clj:321)
	clojure.tools.reader.reader-types/log-source* (reader_types.clj:316)
	clojure.tools.reader/read+string (reader.clj:1029)
	clojure.tools.reader/read+string (reader.clj:1019)
	shadow.cljs.repl/read-one/fn--17402 (repl.clj:628)
	shadow.cljs.repl/read-one (repl.clj:601)
	shadow.cljs.repl/read-one (repl.clj:578)
	shadow.cljs.repl/process-input (repl.clj:703)
	shadow.cljs.repl/process-input (repl.clj:691)
	shadow.cljs.repl/repl-load-file* (repl.clj:195)
	shadow.cljs.repl/repl-load-file* (repl.clj:173)
	shadow.cljs.repl/repl-load-file (repl.clj:231)
	shadow.cljs.repl/repl-load-file (repl.clj:229)
	shadow.cljs.repl/process-read-result (repl.clj:570)
	shadow.cljs.repl/process-read-result (repl.clj:550)
	shadow.cljs.repl/process-input (repl.clj:713)
	shadow.cljs.repl/process-input (repl.clj:691)
	shadow.cljs.devtools.server.worker.impl/eval17950/fn--17953 (impl.clj:698)
	clojure.lang.MultiFn.invoke (MultiFn.java:234)
	shadow.cljs.devtools.server.util/server-thread/fn--17590/fn--17591/fn--17599 (util.clj:283)
	shadow.cljs.devtools.server.util/server-thread/fn--17590/fn--17591 (util.clj:282)
	shadow.cljs.devtools.server.util/server-thread/fn--17590 (util.clj:255)
	java.lang.Thread.run (Thread.java:1583)

I found this old slack thread where @thheller narrowed it down to tools.reader and provided this repro:

(let [rdr (clojure.tools.reader.reader-types/source-logging-push-back-reader
            "(ns demo.test)\n\n(def foo \"foo\");\n(def bar [])\n")]
  (clojure.tools.reader/read+string rdr)
  (clojure.tools.reader/read+string rdr)
  (clojure.tools.reader/read+string rdr))

2 Answers

0 votes
by
selected by
 
Best answer

The issue should be fixed as of shadow-cljs 2.26.0, or rather tools.reader 1.3.7 which was the cause of the problem and is now the declared dependency.

0 votes
by

These seem like they might be different problems. I'm happy to file the latter one, but it's unclear to me if that fixes your original issue?

by
The report above incorrectly involves the shadow-cljs/CLJS REPL, it just happens to surface there due to the use of the read+string function. As shown in the repro snippet you can reproduce the problem entirely without shadow-cljs. I'm confident that the shadow-cljs REPL problem will go away with a tools.reader fix, but I have not looked into the underlying tools.reader issue myself yet.
...