Skip to content

Commit d6ac6db

Browse files
committed
fix a NullPointerException.
gh-16044
1 parent 5e44189 commit d6ac6db

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/web/trace/reactive/ServerWebExchangeTraceableRequest.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2018 the original author or authors.
2+
* Copyright 2012-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,10 +16,13 @@
1616

1717
package org.springframework.boot.actuate.web.trace.reactive;
1818

19+
import java.net.InetAddress;
20+
import java.net.InetSocketAddress;
1921
import java.net.URI;
2022
import java.util.LinkedHashMap;
2123
import java.util.List;
2224
import java.util.Map;
25+
import java.util.Optional;
2326

2427
import org.springframework.boot.actuate.trace.http.TraceableRequest;
2528
import org.springframework.http.server.reactive.ServerHttpRequest;
@@ -45,8 +48,9 @@ class ServerWebExchangeTraceableRequest implements TraceableRequest {
4548
this.method = request.getMethodValue();
4649
this.headers = request.getHeaders();
4750
this.uri = request.getURI();
48-
this.remoteAddress = (request.getRemoteAddress() != null)
49-
? request.getRemoteAddress().getAddress().toString() : null;
51+
this.remoteAddress = Optional.ofNullable(request.getRemoteAddress())
52+
.map(InetSocketAddress::getAddress).map(InetAddress::toString)
53+
.orElse(null);
5054
}
5155

5256
@Override

0 commit comments

Comments
 (0)