JSON objects can be constructed in TL-Script. Using them as the result of a recursion leads to a stack overflow, since the termination condition cannot be detected because the hash codes are not stable.
Solution
JSON objects constructed in TL-Script (e.g. {"v": 5}) are implemented using a special map optimized to store many similar objects (with the same keys but different values) efficiently. However, this map implementation did not adhere to the contract of the Map interface, which requires a special hashcode implementation - or worse, multiple calls to hashCode() produced different results. The hash code calculation is done by AbstractMap, but is based on the entrySet() of the map and this in turn on the hash code implementation of the entries of the entry set. Here a hashcode implementation for the entries of the entry set was added.
Test
- {"v": 5}.recursion(x -> $x["v"] > 0 ? {"v": $x["v"] - 1} : {"v": $x["v"]})
- test.com.top_logic.model.search.expr.TestSearchExpression.testRecursionWithJson()