spockframework / spockframework/spock

Silent test failure: StackOverflowError in SpockComparisonFailure.toString() for objects with circular toString()

Open
#2,413 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
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

  1. Spock test fails, SpockComparisonFailure embeds actual/expected values
  2. SpockComparisonFailure.toString() calls getMessage() calls condition.getRendering()
  3. Condition rendering calls toString() on the assertion values via ExpressionInfoValueRenderer -> RenderUtil.toStringOrDump()
  4. ExpressionInfoValueRenderer.renderValue() catches Exception but not Error
  5. StackOverflowError propagates, 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.