Skip to content

Commit d5ee132

Browse files
committed
fix
1 parent 90c7d51 commit d5ee132

File tree

6 files changed

+26
-11
lines changed

6 files changed

+26
-11
lines changed

conventions/src/main/kotlin/otel.nullaway-conventions.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ tasks {
2626
options.errorprone.nullaway {
2727
customInitializerAnnotations.add("org.openjdk.jmh.annotations.Setup")
2828
excludedFieldAnnotations.add("org.mockito.Mock")
29+
excludedFieldAnnotations.add("org.mockito.InjectMocks")
2930
}
3031
}
3132
}

instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/instrumenter/InstrumenterTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
99
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
1010
import static java.util.Collections.emptyMap;
11+
import static java.util.Objects.requireNonNull;
1112
import static org.assertj.core.api.Assertions.entry;
1213
import static org.mockito.Mockito.when;
1314

@@ -87,7 +88,7 @@ public void onEnd(
8788
Map<String, String> request,
8889
@Nullable Map<String, String> response,
8990
@Nullable Throwable error) {
90-
attributes.put("resp1", response.get("resp1"));
91+
attributes.put("resp1", requireNonNull(response).get("resp1"));
9192
attributes.put("resp2", response.get("resp2"));
9293
}
9394
}
@@ -109,7 +110,7 @@ public void onEnd(
109110
Map<String, String> request,
110111
@Nullable Map<String, String> response,
111112
@Nullable Throwable error) {
112-
attributes.put("resp3", response.get("resp3"));
113+
attributes.put("resp3", requireNonNull(response).get("resp3"));
113114
attributes.put("resp2", response.get("resp2_2"));
114115
}
115116
}

instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/internal/InstrumentationCustomizerTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
99
import static java.util.Collections.singletonList;
10+
import static java.util.Objects.requireNonNull;
1011
import static org.assertj.core.api.Assertions.assertThat;
1112
import static org.assertj.core.api.Assertions.entry;
1213
import static org.mockito.ArgumentMatchers.any;
@@ -338,7 +339,7 @@ public void onEnd(
338339
Map<String, String> request,
339340
@Nullable Map<String, String> response,
340341
@Nullable Throwable error) {
341-
attributes.put("resp1", response.get("resp1"));
342+
attributes.put("resp1", requireNonNull(response).get("resp1"));
342343
attributes.put("resp2", response.get("resp2"));
343344
}
344345
}
@@ -360,7 +361,7 @@ public void onEnd(
360361
Map<String, String> request,
361362
@Nullable Map<String, String> response,
362363
@Nullable Throwable error) {
363-
attributes.put("resp3", response.get("resp3"));
364+
attributes.put("resp3", requireNonNull(response).get("resp3"));
364365
attributes.put("resp2", response.get("resp2_2"));
365366
}
366367
}

instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/internal/InstrumenterContextTest.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package io.opentelemetry.instrumentation.api.internal;
77

88
import static io.opentelemetry.instrumentation.testing.junit.db.SemconvStabilityUtil.maybeStable;
9+
import static java.util.Objects.requireNonNull;
910
import static org.assertj.core.api.Assertions.assertThat;
1011

1112
import io.opentelemetry.api.common.Attributes;
@@ -31,6 +32,7 @@ class InstrumenterContextTest {
3132
@SuppressWarnings({"unchecked", "deprecation"}) // using deprecated DB_SQL_TABLE
3233
@Test
3334
void testSqlSanitizer() {
35+
Object request = new Object(); // dummy request object
3436
String testQuery = "SELECT name FROM test WHERE id = 1";
3537
SqlClientAttributesGetter<Object, Void> getter =
3638
new SqlClientAttributesGetter<Object, Void>() {
@@ -48,11 +50,12 @@ public Collection<String> getRawQueryTexts(Object request) {
4850
cleanup.deferCleanup(InstrumenterContext::reset);
4951

5052
assertThat(InstrumenterContext.get()).isEmpty();
51-
assertThat(spanNameExtractor.extract(null)).isEqualTo("SELECT test");
53+
assertThat(spanNameExtractor.extract(request)).isEqualTo("SELECT test");
5254
// verify that sanitized statement was cached, see SqlStatementSanitizerUtil
5355
assertThat(InstrumenterContext.get()).containsKey("sanitized-sql-map");
5456
Map<String, SqlStatementInfo> sanitizedMap =
55-
(Map<String, SqlStatementInfo>) InstrumenterContext.get().get("sanitized-sql-map");
57+
(Map<String, SqlStatementInfo>)
58+
requireNonNull(InstrumenterContext.get().get("sanitized-sql-map"));
5659
assertThat(sanitizedMap).containsKey(testQuery);
5760

5861
// replace cached sanitization result to verify it is used
@@ -61,7 +64,7 @@ public Collection<String> getRawQueryTexts(Object request) {
6164
SqlStatementInfo.create("SELECT name2 FROM test2 WHERE id = ?", "SELECT", "test2"));
6265
{
6366
AttributesBuilder builder = Attributes.builder();
64-
attributesExtractor.onStart(builder, Context.root(), null);
67+
attributesExtractor.onStart(builder, Context.root(), request);
6568
assertThat(builder.build().get(maybeStable(DbIncubatingAttributes.DB_SQL_TABLE)))
6669
.isEqualTo("test2");
6770
}
@@ -70,7 +73,7 @@ public Collection<String> getRawQueryTexts(Object request) {
7073
sanitizedMap.clear();
7174
{
7275
AttributesBuilder builder = Attributes.builder();
73-
attributesExtractor.onStart(builder, Context.root(), null);
76+
attributesExtractor.onStart(builder, Context.root(), request);
7477
assertThat(builder.build().get(maybeStable(DbIncubatingAttributes.DB_SQL_TABLE)))
7578
.isEqualTo("test");
7679
}

instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/semconv/http/HttpClientAttributesExtractorTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,13 @@ static class TestHttpClientAttributesGetter
5050
implements HttpClientAttributesGetter<Map<String, String>, Map<String, String>> {
5151

5252
@Override
53+
@Nullable
5354
public String getUrlFull(Map<String, String> request) {
5455
return request.get("urlFull");
5556
}
5657

5758
@Override
59+
@Nullable
5860
public String getHttpRequestMethod(Map<String, String> request) {
5961
return request.get("method");
6062
}
@@ -66,13 +68,15 @@ public List<String> getHttpRequestHeader(Map<String, String> request, String nam
6668
}
6769

6870
@Override
71+
@Nullable
6972
public Integer getHttpResponseStatusCode(
7073
Map<String, String> request, Map<String, String> response, @Nullable Throwable error) {
7174
String value = response.get("statusCode");
7275
return value == null ? null : Integer.parseInt(value);
7376
}
7477

7578
@Override
79+
@Nullable
7680
public List<String> getHttpResponseHeader(
7781
Map<String, String> request, Map<String, String> response, String name) {
7882
String value = response.get("header." + name);

instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/semconv/http/HttpServerAttributesExtractorTest.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import static java.util.Collections.emptyList;
2727
import static java.util.Collections.emptyMap;
2828
import static java.util.Collections.singletonList;
29+
import static java.util.Objects.requireNonNull;
2930
import static org.assertj.core.api.Assertions.entry;
3031

3132
import io.opentelemetry.api.common.AttributeKey;
@@ -52,11 +53,13 @@ static class TestHttpServerAttributesGetter
5253
implements HttpServerAttributesGetter<Map<String, String>, Map<String, String>> {
5354

5455
@Override
56+
@Nullable
5557
public String getHttpRequestMethod(Map<String, String> request) {
5658
return request.get("method");
5759
}
5860

5961
@Override
62+
@Nullable
6063
public String getUrlScheme(Map<String, String> request) {
6164
return request.get("urlScheme");
6265
}
@@ -74,6 +77,7 @@ public String getUrlQuery(Map<String, String> request) {
7477
}
7578

7679
@Override
80+
@Nullable
7781
public String getHttpRoute(Map<String, String> request) {
7882
return request.get("route");
7983
}
@@ -85,6 +89,7 @@ public List<String> getHttpRequestHeader(Map<String, String> request, String nam
8589
}
8690

8791
@Override
92+
@Nullable
8893
public Integer getHttpResponseStatusCode(
8994
Map<String, String> request, Map<String, String> response, @Nullable Throwable error) {
9095
String value = response.get("statusCode");
@@ -115,15 +120,15 @@ public String getNetworkType(
115120
@Nullable
116121
@Override
117122
public String getNetworkProtocolName(
118-
Map<String, String> request, Map<String, String> response) {
123+
Map<String, String> request, @Nullable Map<String, String> response) {
119124
return request.get("networkProtocolName");
120125
}
121126

122127
@Nullable
123128
@Override
124129
public String getNetworkProtocolVersion(
125-
Map<String, String> request, Map<String, String> response) {
126-
return request.get("networkProtocolVersion");
130+
Map<String, String> request, @Nullable Map<String, String> response) {
131+
return requireNonNull(response).get("networkProtocolVersion");
127132
}
128133

129134
@Nullable

0 commit comments

Comments
 (0)