Skip to content

Commit a4f9f15

Browse files
committed
Manual fix items for servlet-common:library
1 parent ccb6a66 commit a4f9f15

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

instrumentation/servlet/servlet-2.2/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/servlet/v2_2/Servlet2HttpAttributesGetter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public Integer getHttpResponseStatusCode(
2929
@Nullable Throwable error) {
3030
HttpServletResponse response = responseContext.response();
3131

32-
if (!accessor.isResponseCommitted(response) && error != null) {
32+
if (response != null && !accessor.isResponseCommitted(response) && error != null) {
3333
// if response is not committed and there is a throwable set status to 500 /
3434
// INTERNAL_SERVER_ERROR, due to servlet spec
3535
// https://javaee.github.io/servlet-spec/downloads/servlet-4.0/servlet-4_0_FINAL.pdf:

instrumentation/servlet/servlet-common/library/src/main/java/io/opentelemetry/instrumentation/servlet/internal/ServletHttpAttributesGetter.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
package io.opentelemetry.instrumentation.servlet.internal;
77

8+
import static java.util.Collections.emptyList;
9+
810
import io.opentelemetry.instrumentation.api.semconv.http.HttpServerAttributesGetter;
911
import java.util.List;
1012
import javax.annotation.Nullable;
@@ -83,6 +85,10 @@ public List<String> getHttpResponseHeader(
8385
ServletRequestContext<REQUEST> requestContext,
8486
ServletResponseContext<RESPONSE> responseContext,
8587
String name) {
88+
RESPONSE response = responseContext.response();
89+
if (response == null) {
90+
return emptyList();
91+
}
8692
return accessor.getResponseHeaderValues(responseContext.response(), name);
8793
}
8894

instrumentation/servlet/servlet-common/library/src/main/java/io/opentelemetry/instrumentation/servlet/internal/ServletResponseContext.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,25 @@
55

66
package io.opentelemetry.instrumentation.servlet.internal;
77

8+
import static java.util.Objects.requireNonNull;
9+
10+
import javax.annotation.Nullable;
11+
812
/**
913
* This class is internal and is hence not for public use. Its APIs are unstable and can change at
1014
* any time.
1115
*/
1216
public class ServletResponseContext<T> {
13-
private final T response;
17+
@Nullable private final T response;
1418
// used for servlet 2.2 where request status can't be extracted from HttpServletResponse
15-
private Integer status;
16-
private Long timeout;
19+
@Nullable private Integer status;
20+
@Nullable private Long timeout;
1721

18-
public ServletResponseContext(T response) {
22+
public ServletResponseContext(@Nullable T response) {
1923
this.response = response;
2024
}
2125

26+
@Nullable
2227
public T response() {
2328
return response;
2429
}
@@ -28,7 +33,7 @@ public void setStatus(int status) {
2833
}
2934

3035
public int getStatus() {
31-
return status;
36+
return requireNonNull(status);
3237
}
3338

3439
public boolean hasStatus() {
@@ -40,7 +45,7 @@ public void setTimeout(long timeout) {
4045
}
4146

4247
public long getTimeout() {
43-
return timeout;
48+
return requireNonNull(timeout);
4449
}
4550

4651
public boolean hasTimeout() {

0 commit comments

Comments
 (0)