Skip to content

Commit 5b35863

Browse files
authored
protect jsp decorator from NPE (#10250)
* protect base and jsp decorators from NPE * revert nullchecks on base decorator * check for null before setting a tag
1 parent 6d9873a commit 5b35863

File tree

1 file changed

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

1 file changed

+8
-8
lines changed

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

Lines changed: 8 additions & 8 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,14 @@ 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 {
71-
span.setTag(
72-
"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());
68+
// note: getRequestURL is supposed to always be nonnull - however servlet wrapping can happen
69+
// and we never know if ever this can happen
70+
final StringBuffer requestURL = req.getRequestURL();
71+
if (requestURL != null && requestURL.length() > 0) {
72+
span.setTag("jsp.requestURL", (new URI(requestURL.toString())).normalize().toString());
73+
}
74+
} catch (final Throwable ignored) {
75+
// logging here will be too verbose
7676
}
7777
}
7878
}

0 commit comments

Comments
 (0)