Description
Karate v2 crashes with StackOverflowError when a variable contains a circular reference (an object that directly or indirectly points back to itself).
Additional details- I originally saw the issue when testing the fix for #2870 in 2.0.10.RC1 and saw the note here - https://github.com/karatelabs/karate/blob/main/karate-gatling/src/main/scala/io/karatelabs/gatling/KarateScalaActions.scala#L151, but the issue does not seem limited to the performance tests.
Steps to Reproduce
- Create a feature file using the snippets below.
Feature: hashCode StackOverflow - circular reference reproduction
Scenario: Create circular reference in variables
# Create an object with a self-reference (circular)
* def obj = { name: 'test', items: [1, 2, 3] }
* eval obj.self = obj
# Verify the circular reference exists — this will FAIL if obj.self is not obj
* match obj.self.name == 'test'
* match obj.self.self.name == 'test'
* print 'Circular reference confirmed'
Expected Behavior
- The test should successfully execute and pass (v1 behavior). Attached is the screenshot from v1 result.
Actual Behavior
- The test crashes at run time with below stacktrace.
14:16:37.232 [com.intuit.karate.Main.main()] INFO karate.scenario - Circular reference confirmed
[WARNING]
java.lang.StackOverflowError
at java.util.LinkedHashMap.entrySet (LinkedHashMap.java:883)
at java.util.AbstractMap.hashCode (AbstractMap.java:499)
at java.util.Objects.hashCode (Objects.java:97)
at java.util.HashMap$Node.hashCode (HashMap.java:299)
at java.util.AbstractMap.hashCode (AbstractMap.java:500)
at java.util.Objects.hashCode (Objects.java:97)
at java.util.HashMap$Node.hashCode (HashMap.java:299)
at java.util.AbstractMap.hashCode (AbstractMap.java:500)
at java.util.Objects.hashCode (Objects.java:97)
14:41:56.709 [gatling-1-1] ERROR i.k.gatling.KarateScalaAction - Gatling crashed: j.l.StackOverflowError
java.lang.StackOverflowError
at java.base/java.util.LinkedHashMap$LinkedEntryIterator.<init>(LinkedHashMap.java:1058)
at java.base/java.util.LinkedHashMap$LinkedEntrySet.iterator(LinkedHashMap.java:915)
at java.base/java.util.AbstractMap.hashCode(AbstractMap.java:499)
at java.base/java.util.Objects.hashCode(Objects.java:97)
at java.base/java.util.HashMap$Node.hashCode(HashMap.java:299)
at java.base/java.util.AbstractMap.hashCode(AbstractMap.java:500)
at java.base/java.util.Objects.hashCode(Objects.java:97)
at java.base/java.util.HashMap$Node.hashCode(HashMap.java:299)
at java.base/java.util.AbstractMap.hashCode(AbstractMap.java:500)
at java.base/java.util.Objects.hashCode(Objects.java:97)
Karate Version
2.0.9
Java Version
25.0.2
Operating System
macOS
Description
Karate v2 crashes with StackOverflowError when a variable contains a circular reference (an object that directly or indirectly points back to itself).
Additional details- I originally saw the issue when testing the fix for #2870 in 2.0.10.RC1 and saw the note here - https://github.com/karatelabs/karate/blob/main/karate-gatling/src/main/scala/io/karatelabs/gatling/KarateScalaActions.scala#L151, but the issue does not seem limited to the performance tests.
Steps to Reproduce
Expected Behavior
Actual Behavior
Karate Version
2.0.9
Java Version
25.0.2
Operating System
macOS