Avoid NPEs in DefaultServerRequestObservationConvention
In some cases, the default response status of a `ServerWebExchange` can be `null`, especially when the response is not available or the server implementation does not set a default response status. This commit ensures that the status code is available when deriving `KeyValue` information from it, or uses a fallback value for the key value. Fixes gh-29359
This commit is contained in:
@@ -141,6 +141,16 @@ class DefaultServerRequestObservationConventionTests {
|
||||
.contains(KeyValue.of("http.url", "/test/resource"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void supportsNullStatusCode() {
|
||||
ServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/test/resource"));
|
||||
ServerRequestObservationContext context = new ServerRequestObservationContext(exchange);
|
||||
|
||||
assertThat(this.convention.getLowCardinalityKeyValues(context))
|
||||
.contains(KeyValue.of("status", "UNKNOWN"),
|
||||
KeyValue.of("exception", "none"), KeyValue.of("outcome", "UNKNOWN"));
|
||||
}
|
||||
|
||||
private static PathPattern getPathPattern(String pattern) {
|
||||
PathPatternParser pathPatternParser = new PathPatternParser();
|
||||
return pathPatternParser.parse(pattern);
|
||||
|
||||
Reference in New Issue
Block a user