-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Fix flood json string can not be null or empty from mapping matcher #2247
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like it's quite urgent based on votes.
Would be nice to improve propagation.
src/main/java/com/github/tomakehurst/wiremock/matching/MatchesJsonPathPattern.java
Outdated
Show resolved
Hide resolved
src/main/java/com/github/tomakehurst/wiremock/matching/MatchesJsonPathPattern.java
Outdated
Show resolved
Hide resolved
de163d6
to
a05a620
Compare
Definitely needs a fix. Leaving to @tomakehurst to comments on the implementation style, the NPE approach is a matter for discussion |
@oleg-nenashev thanks. Yes the reason in which I was explicit with the NPE is that I want to guarantee that specific error and capture it accordingly in isAdvancedMatch, otherwise if I rethrow the initial error in getExpressionResult, there's no guarantee that isAdvancedMatch function captures the same error in the future. If @tomakehurst you have a better suggestion, I'm happy to make the change. |
@@ -110,6 +112,8 @@ protected MatchResult isAdvancedMatch(String value) { | |||
} catch (SubExpressionException e) { | |||
notifier().info(e.getMessage()); | |||
return MatchResult.noMatch(SubEvent.warning(e.getMessage())); | |||
} catch (NullPointerException e) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not keen on catching NPE. Something like this might be better (around line 94):
if (expressionResult == null || expressionResult.isEmpty()) {
if (AbsentPattern.class.isAssignableFrom(valuePattern.getClass())) {
expressionResult = ListOrSingle.of((String) null);
} else {
return MatchResult.noMatch();
}
}
@@ -110,6 +112,8 @@ protected MatchResult isAdvancedMatch(String value) { | |||
} catch (SubExpressionException e) { | |||
notifier().info(e.getMessage()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could just drop this completely. I'm not sure it's really helping, and I plan to remove all of these at some point anyway now that we've got sub-events.
An additional test case or two would definitely be a good idea also |
a05a620
to
7484bb5
Compare
7484bb5
to
ee764bc
Compare
@tomakehurst I followed your suggestion of removing the notifier and by that we don't need to catch the specific error. Do you think we should go in this direction or should I rework the other solution? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would put the message to the debug
-level logging, but otherwise +1
LGTM. I suspect we now also have this problem in terms of stacking up a loads of sub-events for the same reason, but we can address this separately. |
Yeah, very likely |
When using body patterns and matchesJsonPath with either
$.
or$[?.
there are several occasions that wiremock throws a warning with the error:Warning: JSON path expression {Expression} failed to match document 'null' because of error 'json string can not be null or empty'
This floods the entire wiremock logs leaving verbose pretty useless.
References
#1817
Submitter checklist