Skip to content

Commit 5d61672

Browse files
committed
protect base and jsp decorators from NPE
1 parent 45bc239 commit 5d61672

File tree

2 files changed

+7
-7
lines changed
  • dd-java-agent
    • agent-bootstrap/src/main/java/datadog/trace/bootstrap/instrumentation/decorator
    • instrumentation/jsp-2.3/src/main/java/datadog/trace/instrumentation/jsp

2 files changed

+7
-7
lines changed

dd-java-agent/agent-bootstrap/src/main/java/datadog/trace/bootstrap/instrumentation/decorator/BaseDecorator.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@ public AgentSpan afterStart(final AgentSpan span) {
7878
}
7979

8080
public ContextScope beforeFinish(final ContextScope scope) {
81-
beforeFinish(scope.context());
81+
if (scope != null) {
82+
beforeFinish(scope.context());
83+
}
8284
return scope;
8385
}
8486

dd-java-agent/instrumentation/jsp-2.3/src/main/java/datadog/trace/instrumentation/jsp/JSPDecorator.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,9 @@
55
import datadog.trace.bootstrap.instrumentation.api.UTF8BytesString;
66
import datadog.trace.bootstrap.instrumentation.decorator.BaseDecorator;
77
import java.net.URI;
8-
import java.net.URISyntaxException;
98
import javax.servlet.RequestDispatcher;
109
import javax.servlet.http.HttpServletRequest;
11-
import javax.servlet.jsp.HttpJspPage;
1210
import org.apache.jasper.JspCompilationContext;
13-
import org.slf4j.LoggerFactory;
1411

1512
public class JSPDecorator extends BaseDecorator {
1613
public static final CharSequence JSP_COMPILE = UTF8BytesString.create("jsp.compile");
@@ -68,11 +65,12 @@ public void onRender(final AgentSpan span, final HttpServletRequest req) {
6865
// HttpServletRequest#getRequestURL(),
6966
// normalizing the URL should remove those symbols for readability and consistency
7067
try {
68+
// note: getRequestURL is supposed to always be nonnull - however servlet wrapping can happen
69+
// and we never know if ever this can happen
7170
span.setTag(
7271
"jsp.requestURL", (new URI(req.getRequestURL().toString())).normalize().toString());
73-
} catch (final URISyntaxException uriSE) {
74-
LoggerFactory.getLogger(HttpJspPage.class)
75-
.debug("Failed to get and normalize request URL: {}", uriSE.getMessage());
72+
} catch (final Throwable ignored) {
73+
// logging here will be too verbose
7674
}
7775
}
7876
}

0 commit comments

Comments
 (0)