Skip to content

wrapValueWithQuotes throws NullPointer when value is null (Cannot invoke "Object.toString()" because "value" is null) #2117

@fireplace009

Description

@fireplace009

Java 21
<spring-cloud-contract.version>4.1.3</spring-cloud-contract.version>

Describe the bug

When running the maven plugin, my contract.yaml has a bodyFromFile value.
This file is a .json containing (amongst other things) an array with values.
One of these value can be null

Sample

{
  "rows": [
    {
      "values": [
        "2023-10-19 08:39:55",
        "B",
        "N",
        "",
        "100",
        "01",
        1,
        1369,
        "100",
        null,
        null,
        null
      ],
  ]
}

In the class DelegatingJsonVerifiable this method:

    private static String wrapValueWithQuotes(Object value) {
        return value instanceof String ? "\"" + stringWithEscapedQuotes(value) + "\"" : value.toString();
    }

does not take into account that the value can be null - (value instanceof String is false => value.toString throws NPE

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions