pact-foundation / pact-jvm

JVM version of Pact. Enables consumer driven contract testing, providing a mock service and DSL for the consumer project, and interaction playback and verification for the service provider project.
https://docs.pact.io
Apache License 2.0
1.08k stars 479 forks source link

java.lang.StackOverflowError for large PactDslJsonBody #1286

Open wesleythomaswilliams opened 3 years ago

wesleythomaswilliams commented 3 years ago

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: `au.com.dius

pact-jvm-provider-maven 4.0.10` 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 commented 3 years ago

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 commented 3 years ago

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)