Skip to content

Commit dadb6f0

Browse files
committed
fix null
1 parent 8d91e6f commit dadb6f0

4 files changed

Lines changed: 36 additions & 0 deletions

File tree

dd-java-agent/instrumentation/vertx/vertx-web/vertx-web-3.4/src/main/java/datadog/trace/instrumentation/vertx_3_4/server/RouteUpdateHelper.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ public static void updateRouteFromContext(
2424
Route currentRoute;
2525
try {
2626
currentRoute = routingContext.currentRoute();
27+
if (currentRoute == null) {
28+
return;
29+
}
2730
} catch (final RuntimeException ignored) {
2831
// Vert.x can call RouteState.matches before currentRoute is set on the context.
2932
return;

dd-java-agent/instrumentation/vertx/vertx-web/vertx-web-3.4/src/test/java/server/RouteHandlerWrapperTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,21 @@ void updateRouteIgnoresUnavailableCurrentRouteFallback() {
102102
verifyNoMoreInteractions(parentSpan, handlerSpan);
103103
}
104104

105+
@Test
106+
void updateRouteIgnoresNullCurrentRouteFallback() {
107+
TestRoutingContext context = new TestRoutingContext("/items/123", "GET");
108+
AgentSpan parentSpan = mock(AgentSpan.class);
109+
AgentSpan handlerSpan = mock(AgentSpan.class);
110+
111+
assertDoesNotThrow(
112+
() ->
113+
RouteUpdateHelper.updateRouteFromMatchedRoute(
114+
context.instance(), new Object(), parentSpan, handlerSpan));
115+
116+
context.verifyUnset("dd." + Tags.HTTP_ROUTE);
117+
verifyNoMoreInteractions(parentSpan, handlerSpan);
118+
}
119+
105120
private static final class TestRoutingContext implements InvocationHandler {
106121
private final RoutingContext instance;
107122
private final HttpServerRequest request;

dd-java-agent/instrumentation/vertx/vertx-web/vertx-web-4.0/src/main/java/datadog/trace/instrumentation/vertx_4_0/server/RouteUpdateHelper.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ public static void updateRouteFromContext(
2424
Route currentRoute;
2525
try {
2626
currentRoute = routingContext.currentRoute();
27+
if (currentRoute == null) {
28+
return;
29+
}
2730
} catch (final RuntimeException ignored) {
2831
// Vert.x can call RouteState.matches before currentRoute is set on the context.
2932
return;

dd-java-agent/instrumentation/vertx/vertx-web/vertx-web-4.0/src/test/java/server/RouteHandlerWrapperTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,21 @@ void updateRouteIgnoresUnavailableCurrentRouteFallback() {
105105
verifyNoMoreInteractions(parentSpan, handlerSpan);
106106
}
107107

108+
@Test
109+
void updateRouteIgnoresNullCurrentRouteFallback() {
110+
TestRoutingContext context = new TestRoutingContext("/items/123", HttpMethod.GET);
111+
AgentSpan parentSpan = mock(AgentSpan.class);
112+
AgentSpan handlerSpan = mock(AgentSpan.class);
113+
114+
assertDoesNotThrow(
115+
() ->
116+
RouteUpdateHelper.updateRouteFromMatchedRoute(
117+
context.instance(), new Object(), parentSpan, handlerSpan));
118+
119+
context.verifyUnset("dd." + Tags.HTTP_ROUTE);
120+
verifyNoMoreInteractions(parentSpan, handlerSpan);
121+
}
122+
108123
private static final class TestRoutingContext implements InvocationHandler {
109124
private final RoutingContext instance;
110125
private final HttpServerRequest request;

0 commit comments

Comments
 (0)