Clojure 1.12.7: Lean and testing turn up 17 unreported bugs

A blog author on s.conao3.com checked the core of Clojure 1.12.7 (released 2026-11-18, run on JDK 21) and found 17 bugs they could not find in Clojure's JIRA or on ask.clojure.org. The idea came from Koukyosyumei's Japanese article about formally verifying well-known Rust projects with Lean 4. The author expected nothing to remain in data structures that many people have used since around Clojure 1.0.
There were three methods. Integer and bit arithmetic was modeled in Lean 4, where the bv_decide tactic searches for counterexamples; each one was then reproduced in Clojure, and a fixed version was modeled and proved. The large collections were compared with their java.util counterparts under the same random operations. Java interop calls were compared with and without type hints.
First, a vector-of (a vector backed by primitive arrays, implemented in gvec.clj) that goes through drop 1 and then reduce never returns once it holds 65505 or more elements. Line 79 uses the mask 0xffe0 to round down to a multiple of 32, but it also clears bit 16 and above. The chunk after index 65504 should start at 65536; the mask yields 0, so reduce reads the vector over and over. The mask has been there since a 2010 commit.
Second, in the hash array mapped trie (HAMT) behind hash-map, HashCollisionNode.without gives the rebuilt node the hash of the key passed to dissoc instead of the node's own this.hash. If that key is = to the stored key but hashes differently, as a Clojure vector and a Java ArrayList can, a later assoc can leave a map that prints a key while get returns nil for it. disj on a hash-set shares the bug; transient dissoc! does not. Changing the line to this.hash fixed the example.
Third, the same .removeIf call with a set as the predicate throws ClassCastException when the list's type is known, but removes elements when the call goes through reflection. The other two detailed bugs are an int overflow in the drop implementation for string seqs (the author says the vector seq version adds ints the same way) and assoc with index -1 on a subvec, which silently overwrites an element of the underlying vector. Another 12 bugs have smaller impact; the author reproduced each on 1.12.7.
Much of the core held up. Hash maps and sets matched java.util over 3 million operations, PersistentTreeMap matched TreeMap and kept its red-black invariants, and vectors matched ArrayList around every tree boundary tested.
Key facts
- 17 bugs in Clojure 1.12.7 that the author could not find in Clojure's JIRA or on ask.clojure.org; 5 are described and 12 are called smaller in impact.
- drop 1 followed by reduce on a vector-of never returns at 65505 or more elements because the 0xffe0 mask in gvec.clj also clears bit 16 and above.
- HashCollisionNode.without records the wrong hash, so after dissoc and assoc a map can print a key that get cannot find.
- The same .removeIf call throws or removes elements depending on whether a type hint lets the compiler avoid reflection.
- No mismatch with java.util in 3 million hash map and set operations, or around the tested vector tree boundaries.
Why it matters
Clojure's persistent data structures have had many users since around version 1.0, which is why the author expected no bugs to remain. The trie and vector tree did pass the differential tests. The author places the bugs in separate code outside the trees and where two mechanisms meet, such as = and hashing. The vector-of mask has survived since 2010.
The approach builds on work in Rust: Koukyosyumei ported well-known Rust projects into a form provable in Lean 4 and found bugs where proofs failed. The author followed the procedure described in hirosassa/lean-verify, which models a small function and checks it for all inputs.
Who it affects
Clojure developers whose code hits these paths. That includes reducing a large vector-of after drop; hash maps or hash sets with colliding keys that can be = yet hash differently, such as Clojure vectors and Java ArrayLists (a mismatch tracked as CLJ-1372); and passing Clojure functions to Java methods that expect a boolean-returning functional interface.
Also exposed are drop with a very large count on string seqs or vector seqs, through the IDrop implementations added in 1.12, and assoc with a negative index on a subvec. CLJ-962 fixed that last kind of bug in nth, but assoc still has it.
How to use it
The post gives snippets you can run. The vector-of case returns 2145354256 at 65504 elements and hangs at 65505, while the same drop and reduce on an ordinary vec of 65505 elements returns normally. For the mask, the author's Lean model uses (bit-not 0x1f), proved correct when the position is a multiple of 32 below 0x7fffffe0. For the collision node, the change is this.hash in PersistentHashMap.java. For string seq drop, it is comparing n with the remaining length, s.length() - i.
To repeat the method, model one small function in Lean, with Java long and int as BitVec 64 and BitVec 32, write a property against a naive specification computed at a wider width, and let bv_decide look for counterexamples. It suits only small functions that reduce to integer and bit arithmetic.
How solid is it
This is one author's blog post, with concrete code, outputs and Lean theorems. The author reproduced the bugs on 1.12.7, and for the collision node also compiled a patched class that made the example return :B as expected. To check novelty, they searched JIRA through its REST API and ask.clojure.org through web and site search.
The Lean proofs hold for the models shown in the post. The author checked that each model matches the Java code by comparing it with the source and with reproduced behavior. On numerics, Lean proved the fast path check for addition and subtraction at 64 bits and clojure.core/mod up to 32 bits.
Risks and caveats
Lean did not verify Clojure's core as a whole. The large data structures were tested, not proved: 1,500 operations for each of 2,000 seeds on the HAMT, and comparisons around vector sizes 32, 1056, 32800 and 1048608. A clean run does not rule out defects, and the collision node bug sits in a structure whose differential tests showed no mismatch.
For multiplication, bv_decide timed out at 16 bits, so only 8 and 10 bits were checked. The post does not describe the other 12 bugs. Nor does it say the new bugs were reported to Clojure maintainers, acknowledged, or fixed upstream.
“The bugs sat in separate code outside the trees, and in places where two mechanisms meet, such as = and hashing.”
— the blog author, s.conao3.com