Skip to content

Commit d2bcc97

Browse files
authored
Merge pull request #9935 from jaikiran/qk-9882
Fix NullPointerException(s) when dealing with remote and local address returned by HTTP request
2 parents 4ce2c71 + da0be1d commit d2bcc97

File tree

4 files changed

+18
-2
lines changed

4 files changed

+18
-2
lines changed

extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/attribute/LocalIPAttribute.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ private LocalIPAttribute() {
2020
@Override
2121
public String readAttribute(final RoutingContext exchange) {
2222
SocketAddress localAddress = exchange.request().localAddress();
23+
if (localAddress == null) {
24+
return null;
25+
}
2326
return localAddress.host();
2427
}
2528

extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/attribute/LocalPortAttribute.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.quarkus.vertx.http.runtime.attribute;
22

3+
import io.vertx.core.net.SocketAddress;
34
import io.vertx.ext.web.RoutingContext;
45

56
/**
@@ -19,7 +20,11 @@ private LocalPortAttribute() {
1920

2021
@Override
2122
public String readAttribute(final RoutingContext exchange) {
22-
return Integer.toString(exchange.request().localAddress().port());
23+
final SocketAddress localAddr = exchange.request().localAddress();
24+
if (localAddr == null) {
25+
return null;
26+
}
27+
return Integer.toString(localAddr.port());
2328
}
2429

2530
@Override

extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/attribute/RemoteHostAttribute.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.quarkus.vertx.http.runtime.attribute;
22

3+
import io.vertx.core.net.SocketAddress;
34
import io.vertx.ext.web.RoutingContext;
45

56
/**
@@ -19,7 +20,11 @@ private RemoteHostAttribute() {
1920

2021
@Override
2122
public String readAttribute(final RoutingContext exchange) {
22-
return exchange.request().remoteAddress().host();
23+
final SocketAddress remoteAddr = exchange.request().remoteAddress();
24+
if (remoteAddr == null) {
25+
return null;
26+
}
27+
return remoteAddr.host();
2328
}
2429

2530
@Override

extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/attribute/RemoteIPAttribute.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ private RemoteIPAttribute() {
2121
@Override
2222
public String readAttribute(final RoutingContext exchange) {
2323
final SocketAddress sourceAddress = exchange.request().remoteAddress();
24+
if (sourceAddress == null) {
25+
return null;
26+
}
2427
return sourceAddress.host();
2528
}
2629

0 commit comments

Comments
 (0)