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.07k stars 475 forks source link

PactBrokerClient throws index-out-of-bounds when 'can-i-deploy' is called for a new tag #1814

Closed alwidas closed 1 week ago

alwidas commented 3 weeks ago

We are using the maven-plugin (au.com.dius.pact.provider:maven:4.5.10` for most of our PACT Steps during CI & Deployment.

Whenever we try to call can-i-deploy for a provider on a new tag (no consumers yet!), it fails with

Execution default-cli of goal au.com.dius.pact.provider:maven:4.5.10:can-i-deploy failed: Index 0 out of bounds for length 0

The cause is obvious. When we ask with a (not yet) known tag, the server (PactFlow) sends this JSON response:

{
  "summary": {
    "deployable": true,
    "reason": "There are no missing dependencies",
    "success": 0,
    "failed": 0,
    "unknown": 0
  },
  "notices": [
    {
      "type": "success",
      "text": "There are no missing dependencies"
    }
  ],
  "matrix": []
}

=> "matrix" is an empty array

The code indeed checks if the array is null (?.), but after that it calls get(0) on the empty array.

https://github.com/pact-foundation/pact-jvm/blob/521e26513dbed7375f24d138615005eec5f27080/core/pactbroker/src/main/kotlin/au/com/dius/pact/core/pactbroker/PactBrokerClient.kt#L1040-L1041

As this part is only executed to deliver the successful verification results, it should be no problem to skip that part entirely, if we don't have a result at all. Sorry that i don't come up with a PR, but i'm not used to Kotlin at all, and the fix should be fairly easy to implement.

Interesting observation as a side note: when using the CLI (pact-broker), no error occurs.

github-actions[bot] commented 3 weeks ago

🤖 Great news! We've labeled this issue as smartbear-supported and created a tracking ticket in PactFlow's Jira (PACT-2181). We'll keep work public and post updates here. Meanwhile, feel free to check out our docs. Thanks for your patience!

rholshausen commented 3 weeks ago

I've released 4.5.11 with the fix

alwidas commented 2 weeks ago

Thank you so much for the incredibly fast reaction. Now it works as expected. 👍