Lean and differential testing find 17 unreported bugs in Clojure's core
The author checked parts of Clojure's core, written in Java, with Lean 4[1], a tool for proving properties of code, and with differential testing[2], which compares results against Java's java.util collections. Inspired by a Japanese article on formally verifying Rust projects, the author expected few bugs in Clojure's persistent data structures but found 17 bugs that were not reported in Clojure's JIRA or on ask.clojure.org. The tests used Clojure 1.12.7, released on 18 November, and JDK 21.
One bug makes reduce on a vector-of never return once the vector holds 65505 or more elements. A mask in gvec.clj clears bit 16 and above, so the start of the next chunk becomes 0 and reduce reads the vector again and again. Another bug is in the collision node of a HAMT[3], where dissoc records the hash of the key passed in instead of the node's own hash, which can make a remaining key unreachable. A third bug is that calling removeIf on a Java list gives different results with and without a type hint, because reflection converts the boolean return value differently.
The HAMT itself showed no mismatches in 3 million operations of differential testing. The bugs were found in separate code and in places where two mechanisms meet, such as = and hashing.
Read the original s.conao3.comDiscussion
Sources
-
Conao3 Notes
I checked Clojure's core with Lean and found 17 unreported bugs

