spockframework / spockframework/spock
Silent test failure: StackOverflowError in SpockComparisonFailure.toString() for objects with circular toString()
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 3.6k
- Forks
- 483
- PR merge metrics
- No merged PRs in 30d
Description
Describe the bug
Problem
When a Spock test fails with an equality assertion involving an object that has a circular toString(), SpockComparisonFailure.toString() triggers a StackOverflowError. This causes test runners like Surefire to silently drop the test result, making failures invisible. The build appears green.
Root cause
- Spock test fails,
SpockComparisonFailureembeds actual/expected values SpockComparisonFailure.toString()callsgetMessage()callscondition.getRendering()- Condition rendering calls
toString()on the assertion values viaExpressionInfoValueRenderer->RenderUtil.toStringOrDump() ExpressionInfoValueRenderer.renderValue()catchesExceptionbut notErrorStackOverflowErrorpropagates, crashing the test runner's reporting
Comparison with JUnit 5
JUnit 5 does not have this issue. AssertionFailedError stores values without triggering recursive toString() during reporting.
Reproduction
An object with a circular toString() (e.g. self field pointing back to the same instance) used in a failing equality assertion is enough to trigger the bug.
AI disclosure
The analysis of the root cause was developed with significant assistance from an AI coding assistant. The bug was first identified in a separate MRE project using Surefire, then traced through the Spock source code with the AI's help.
To Reproduce
https://github.com/rmie/spock/tree/fix/silent-failure-circular-tostring
Expected behavior
at a minimum, the must not fail silently
Actual behavior
it fails silently
Java version
all tested version are affected
Buildtool version
all tested version are affected
What operating system are you using
Windows
Dependencies
https://github.com/rmie/spock/actions/runs/33632078870
Additional context
n/a
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Use the linked reproduction to trigger a failing equality assertion with an object whose toString() is circular. Trace SpockComparisonFailure.toString() through getMessage(), condition.getRendering(), ExpressionInfoValueRenderer.renderValue(), and RenderUtil.toStringOrDump(); done means the failure is reported instead of silently terminating, with a regression test for the reproduction.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- groovy, java
- Domain
- testing
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100