Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java.lang.StackOverflowError for large PactDslJsonBody #1286

Open
wesleythomaswilliams opened this issue Jan 11, 2021 · 2 comments
Open

java.lang.StackOverflowError for large PactDslJsonBody #1286

wesleythomaswilliams opened this issue Jan 11, 2021 · 2 comments
Labels
bug Indicates an unexpected problem or unintended behavior

Comments

@wesleythomaswilliams
Copy link

A PactDslJsonBody with 432+ lines causes a java.lang.StackOverflowError on the Java 1.8 compiler. I can't include the example directly here, but @uglyog has access via slack and I'm happy to provide directly on request:
https://pact-foundation.slack.com/archives/G01D62WEB60/p1609953945002100

Pact Version:
<groupId>au.com.dius</groupId> <artifactId>pact-jvm-provider-maven</artifactId> <version>4.0.10</version>

Java Version
java -version openjdk version "1.8.0_252" OpenJDK Runtime Environment (AdoptOpenJDK)(build 1.8.0_252-b09) OpenJDK 64-Bit Server VM (AdoptOpenJDK)(build 25.252-b09, mixed mode)

uglyog pushed a commit that referenced this issue Jan 20, 2021
@uglyog uglyog added the bug Indicates an unexpected problem or unintended behavior label Jan 20, 2021
@uglyog
Copy link
Member

uglyog commented Jan 20, 2021

Looks like you can already split the large call chain up. I was about to remove the error by splitting out four objects:

PactDslJsonBody productSpecification = new PactDslJsonBody()
      .integerType("multiPackQuantity", 1)
      .booleanType("copyrightInd", false)
      .stringType("copyrightDets", "sample_data")
      .booleanType("batteryRequired", true)
      .booleanType("batteryIncluded", false)
      .booleanType("beabApproved", false)
      .stringType("beabCertNo", "sample_data")
      .booleanType("plugRequired", false)
      .booleanType("plugIncluded", false)
      .booleanType("bulbRequired", false)
      .booleanType("bulbIncluded", false)
      .decimalType("voltage", 10.10)
      .decimalType("wattage", 10.10);

and then in the main body:

      .object("productSpecification", productSpecification)

This will add "productSpecification" as a object defined by the productSpecification body. You also don't need to call close, it is done for you.

@uglyog
Copy link
Member

uglyog commented Jan 20, 2021

You can now also split out the object definitions with minArrayLike now, ie.

PactDslJsonBody colours = new PactDslJsonBody()
      .stringType("name", "sample_data")
      .booleanType("primary", false)
      .stringType("colourCode", "sample_data")
      .stringType("hexCode", "sample_data")
      .stringType("rgbCode", "sample_data");

minArrayLike("colours", 1, colours)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

2 participants