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

Pact DSL throws NPE when setting an stringType with example set to null #1679

Closed
iekdosha opened this issue Mar 15, 2023 · 2 comments
Closed

Comments

@iekdosha
Copy link

iekdosha commented Mar 15, 2023

I am using consumer version 4.4.7.

Running this code:

String value = null;
new PactDslJsonBody()
      .stringType("myField", value)

will produce NPE:

java.lang.NullPointerException: Cannot invoke "String.toCharArray()" because "examples[0]" is null

It looks like in file PactDslJsonBody.kt method fun stringType(name: String, vararg examples: String): PactDslJsonBody there is not null check before accessing the value:

is JsonValue.Object -> body.add(name, JsonValue.StringValue(examples[0].toCharArray()))
@iekdosha iekdosha changed the title Pact DSL throws NPE when setting an string type with example null Pact DSL throws NPE when setting an stringType with example set to null Mar 15, 2023
@github-actions
Copy link

👋 Hi! The 'smartbear-supported' label has just been added to this issue, which will create an internal tracking ticket in PactFlow's Jira (PACT-888). We will use this to prioritise and assign a team member to this task. All activity will be public on this ticket. For now, sit tight and we'll update this ticket once we have more information on the next steps.

See our documentation for more information.

@rholshausen
Copy link
Contributor

I've updated the DSL to throw IllegalArgumentException instead of NullPointerException

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants