Repository navigation
fix: self-referential thunks produce clean error instead of StackOverflowError - #1020
Merged
stephenamar-db merged 1 commit intoJun 24, 2026
Merged
Conversation
…flowError Motivation: `local x = x; x` caused an uncontrolled java.lang.StackOverflowError with a raw Java stack trace. C++ jsonnet, go-jsonnet, and jrsonnet all produce clean, controlled error messages for self-referential thunks. Modification: - Val.scala: Add `evaluating` boolean flag to LazyExpr. When value is first requested, set the flag to true. If value is requested again while the flag is true, it's a cycle — throw a clean error: "Infinite recursion detected (self-referential thunk)". Result: Self-referential thunks now produce a clean sjsonnet.Error instead of crashing the JVM. Cross-implementation comparison: | Expression | cpp-jsonnet | go-jsonnet | jrsonnet | sjsonnet (before) | sjsonnet (after) | |---|---|---|---|---|---| | local x = x; x | "max stack frames" | "max stack frames" | "infinite recursion" | StackOverflowError 💥 | "Infinite recursion detected" ✅ | | local f() = f(); f() | "max stack frames" | "max stack frames" | "stack overflow" | "Max stack frames" ✅ | "Max stack frames" ✅ | | local x = 1+2; x | 3 | 3 | 3 | 3 ✅ | 3 ✅ |
stephenamar-db
approved these changes
Jun 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fix: self-referential thunks produce clean error instead of StackOverflowError
Motivation
local x = x; x(self-referential thunk) caused an uncontrolledjava.lang.StackOverflowErrorwith raw Java stack trace. C++ jsonnet, go-jsonnet, and jrsonnet all produce clean, controlled error messages.Modification
Val.scala: Addedevaluating: Booleanflag toLazyExpr. Set totrueon first evaluation; if the sameLazyExpris re-entered during evaluation, cycle is detected and"Infinite recursion detected (self-referential thunk)"is thrown.Pendingstate sentinel.error.self_referential_thunk.jsonnetResult
local x = x; xlocal f() = f(); f()local x = 1+2; x3333✅3✅