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

"truncateActual" results in null pointer exceptions #2466

Closed
papiomytoglou opened this issue Oct 27, 2023 · 1 comment · Fixed by #2467
Closed

"truncateActual" results in null pointer exceptions #2466

papiomytoglou opened this issue Oct 27, 2023 · 1 comment · Fixed by #2467
Labels

Comments

@papiomytoglou
Copy link
Contributor

papiomytoglou commented Oct 27, 2023

Proposal

Using a JSON mapping file which includes truncateActual in standalone results in null pointer exceptions for all requests with non-matching URIs or date/time values.

For example, when including the matcher below in a mapping

"queryParameters": {
  "datetime": {
    "equalToDateTime": "now",
    "truncateExpected": "first hour of day",
    "truncateActual": "first hour of day"
  }
}

all requests with matching URIs or datetime values will still be handled correctly but all other requests will result in the following null pointer exception:

java.lang.NullPointerException: Cannot invoke "java.time.ZonedDateTime.truncatedTo(java.time.temporal.TemporalUnit)" because "input" is null

Removing truncateActual stops the exception from being thrown but is not a solution since the two matchers are not equivalent.

Tested in standalone versions 3.0.1, 3.1.0 and 3.2.0

Reproduction steps

Create a JSON file in mappings with the following data:

{
  "request": {
    "method": "GET",
    "urlPath": "/first",
    "queryParameters": {
      "datetime": {
        "equalToDateTime": "now",
        "truncateExpected": "first hour of day",
        "truncateActual": "first hour of day"
      }
    }
  },
  "response": {
    "status": 200,
    "body": "First stub"
  }
}

Create a second JSON file, also in mappings, with the following data:

{
  "request": {
    "method": "GET",
    "urlPath": "/second"
  },
  "response": {
    "status": 200,
    "body": "Second stub"
  }
}

Start wiremock-standalone-3.2.0.jar locally on port 80 only using the above two mappings then open a browser and navigate to the following URIs replacing 2023-10-27 with the current date:

http://localhost/first?datetime=2023-10-27T17:09:10.739Z
# Matches successfully

http://localhost/second
# Matches successfully

http://localhost/first
# Matching URI, absent date/time parameter, returns null pointer exception

http://localhost/third
http://localhost/nonexistent
http://localhost/12345
http://localhost/employee?id=42
# Non-matching URIs, all return null pointer exceptions

http://localhost/first?datetime=2047-01-01T17:09:10.739Z
# Matching URI, non-matching date/time parameter value, returns "Request was not matched" response

http://localhost/nonexistent?datetime=2023-10-27T17:09:10.739Z
# Non-matching URI, matching date/time parameter value, returns "Request was not matched" response

References

No response

@papiomytoglou
Copy link
Contributor Author

It looks like the order the mappings are added with matters. If the mapping containing truncateActual is added last then even the requests with matching URIs return a null pointer exception. So what I described initially is probably the best case scenario.

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

Successfully merging a pull request may close this issue.

1 participant