Skip to content

Commit 11a00dd

Browse files
committed
disable nullaway for tests
1 parent 92da0d7 commit 11a00dd

File tree

9 files changed

+37
-65
lines changed

9 files changed

+37
-65
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ nullaway {
1818

1919
tasks {
2020
withType<JavaCompile>().configureEach {
21-
if (!name.contains("test", ignoreCase = true)) {
21+
if (name.contains("test", ignoreCase = true)) {
22+
options.errorprone.nullaway {
23+
enabled = false
24+
}
25+
} else {
2226
options.errorprone.nullaway {
2327
severity.set(CheckSeverity.ERROR)
2428
}

instrumentation-api-incubator/src/test/java/io/opentelemetry/instrumentation/api/incubator/semconv/messaging/MessagingAttributesExtractorTest.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,11 @@ enum TestGetter implements MessagingAttributesGetter<Map<String, String>, String
135135
INSTANCE;
136136

137137
@Override
138-
@Nullable
139138
public String getSystem(Map<String, String> request) {
140139
return request.get("system");
141140
}
142141

143142
@Override
144-
@Nullable
145143
public String getDestination(Map<String, String> request) {
146144
return request.get("destination");
147145
}
@@ -163,7 +161,6 @@ public boolean isAnonymousDestination(Map<String, String> request) {
163161
}
164162

165163
@Override
166-
@Nullable
167164
public String getConversationId(Map<String, String> request) {
168165
return request.get("conversationId");
169166
}
@@ -183,7 +180,6 @@ public Long getMessageEnvelopeSize(Map<String, String> request) {
183180
}
184181

185182
@Override
186-
@Nullable
187183
public String getMessageId(Map<String, String> request, String response) {
188184
return response;
189185
}

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

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
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;
1211
import static org.assertj.core.api.Assertions.entry;
1312
import static org.mockito.Mockito.when;
1413

@@ -86,9 +85,9 @@ public void onEnd(
8685
AttributesBuilder attributes,
8786
Context context,
8887
Map<String, String> request,
89-
@Nullable Map<String, String> response,
88+
Map<String, String> response,
9089
@Nullable Throwable error) {
91-
attributes.put("resp1", requireNonNull(response).get("resp1"));
90+
attributes.put("resp1", response.get("resp1"));
9291
attributes.put("resp2", response.get("resp2"));
9392
}
9493
}
@@ -108,9 +107,9 @@ public void onEnd(
108107
AttributesBuilder attributes,
109108
Context context,
110109
Map<String, String> request,
111-
@Nullable Map<String, String> response,
110+
Map<String, String> response,
112111
@Nullable Throwable error) {
113-
attributes.put("resp3", requireNonNull(response).get("resp3"));
112+
attributes.put("resp3", response.get("resp3"));
114113
attributes.put("resp2", response.get("resp2_2"));
115114
}
116115
}
@@ -146,8 +145,8 @@ public void extract(
146145
SpanLinksBuilder spanLinks, Context parentContext, Map<String, String> request) {
147146
spanLinks.addLink(
148147
SpanContext.create(
149-
requireNonNull(request.get("linkTraceId")),
150-
requireNonNull(request.get("linkSpanId")),
148+
request.get("linkTraceId"),
149+
request.get("linkSpanId"),
151150
TraceFlags.getSampled(),
152151
TraceState.getDefault()));
153152
}
@@ -161,9 +160,8 @@ public Iterable<String> keys(Map<String, String> carrier) {
161160
}
162161

163162
@Override
164-
@Nullable
165-
public String get(@Nullable Map<String, String> carrier, String key) {
166-
return requireNonNull(carrier).get(key);
163+
public String get(Map<String, String> carrier, String key) {
164+
return carrier.get(key);
167165
}
168166
}
169167

@@ -260,7 +258,7 @@ void server_parent() {
260258
TraceFlags.getSampled(),
261259
TraceState.getDefault()))),
262260
request,
263-
(map, key, value) -> requireNonNull(map).put(key, value));
261+
Map::put);
264262

265263
Context context = instrumenter.start(Context.root(), request);
266264
assertThat(Span.fromContext(context).getSpanContext().isValid()).isTrue();
@@ -288,7 +286,7 @@ void client() {
288286
.addAttributesExtractor(new AttributesExtractor1())
289287
.addAttributesExtractor(new AttributesExtractor2())
290288
.addSpanLinksExtractor(new LinksExtractor())
291-
.buildClientInstrumenter((map, key, value) -> requireNonNull(map).put(key, value));
289+
.buildClientInstrumenter(Map::put);
292290

293291
Map<String, String> request = new HashMap<>(REQUEST);
294292
Context context = instrumenter.start(Context.root(), request);
@@ -329,7 +327,7 @@ void client_error() {
329327
otelTesting.getOpenTelemetry(), "test", unused -> "span")
330328
.addAttributesExtractor(new AttributesExtractor1())
331329
.addAttributesExtractor(new AttributesExtractor2())
332-
.buildClientInstrumenter((map, key, value) -> requireNonNull(map).put(key, value));
330+
.buildClientInstrumenter(Map::put);
333331

334332
Map<String, String> request = new HashMap<>(REQUEST);
335333
Context context = instrumenter.start(Context.root(), request);
@@ -355,7 +353,7 @@ void client_parent() {
355353
otelTesting.getOpenTelemetry(), "test", unused -> "span")
356354
.addAttributesExtractor(new AttributesExtractor1())
357355
.addAttributesExtractor(new AttributesExtractor2())
358-
.buildClientInstrumenter((map, key, value) -> requireNonNull(map).put(key, value));
356+
.buildClientInstrumenter(Map::put);
359357

360358
Context parent =
361359
Context.root()
@@ -422,9 +420,7 @@ void downstream_customSpanKind() {
422420
Instrumenter<Map<String, String>, Map<String, String>> instrumenter =
423421
Instrumenter.<Map<String, String>, Map<String, String>>builder(
424422
otelTesting.getOpenTelemetry(), "test", unused -> "span")
425-
.buildDownstreamInstrumenter(
426-
(map, key, value) -> requireNonNull(map).put(key, value),
427-
SpanKindExtractor.alwaysInternal());
423+
.buildDownstreamInstrumenter(Map::put, SpanKindExtractor.alwaysInternal());
428424

429425
Map<String, String> request = new HashMap<>();
430426
Context context = instrumenter.start(Context.root(), request);
@@ -503,10 +499,8 @@ public void onEnd(Context context, Attributes endAttributes, long endNanos) {
503499
Context context = instrumenter.start(Context.root(), REQUEST);
504500
instrumenter.end(context, REQUEST, RESPONSE, null);
505501

506-
assertThat(Span.fromContext(requireNonNull(startContext.get())).getSpanContext().isValid())
507-
.isTrue();
508-
assertThat(Span.fromContext(requireNonNull(endContext.get())).getSpanContext().isValid())
509-
.isTrue();
502+
assertThat(Span.fromContext(startContext.get()).getSpanContext().isValid()).isTrue();
503+
assertThat(Span.fromContext(endContext.get()).getSpanContext().isValid()).isTrue();
510504
}
511505

512506
@Test

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

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

88
import static java.util.Collections.singletonMap;
9-
import static java.util.Objects.requireNonNull;
109
import static org.mockito.Mockito.verify;
1110

1211
import io.opentelemetry.api.trace.SpanContext;
@@ -20,7 +19,6 @@
2019
import io.opentelemetry.context.propagation.TextMapPropagator;
2120
import io.opentelemetry.instrumentation.api.internal.PropagatorBasedSpanLinksExtractor;
2221
import java.util.Map;
23-
import javax.annotation.Nullable;
2422
import org.junit.jupiter.api.Test;
2523
import org.junit.jupiter.api.extension.ExtendWith;
2624
import org.mockito.Mock;
@@ -62,9 +60,8 @@ public Iterable<String> keys(Map<String, String> carrier) {
6260
}
6361

6462
@Override
65-
@Nullable
66-
public String get(@Nullable Map<String, String> carrier, String key) {
67-
return requireNonNull(carrier).get(key);
63+
public String get(Map<String, String> carrier, String key) {
64+
return carrier.get(key);
6865
}
6966
}
7067
}

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
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;
1110
import static org.assertj.core.api.Assertions.assertThat;
1211
import static org.assertj.core.api.Assertions.entry;
1312
import static org.mockito.ArgumentMatchers.any;
@@ -337,9 +336,9 @@ public void onEnd(
337336
AttributesBuilder attributes,
338337
Context context,
339338
Map<String, String> request,
340-
@Nullable Map<String, String> response,
339+
Map<String, String> response,
341340
@Nullable Throwable error) {
342-
attributes.put("resp1", requireNonNull(response).get("resp1"));
341+
attributes.put("resp1", response.get("resp1"));
343342
attributes.put("resp2", response.get("resp2"));
344343
}
345344
}
@@ -359,9 +358,9 @@ public void onEnd(
359358
AttributesBuilder attributes,
360359
Context context,
361360
Map<String, String> request,
362-
@Nullable Map<String, String> response,
361+
Map<String, String> response,
363362
@Nullable Throwable error) {
364-
attributes.put("resp3", requireNonNull(response).get("resp3"));
363+
attributes.put("resp3", response.get("resp3"));
365364
attributes.put("resp2", response.get("resp2_2"));
366365
}
367366
}

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

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
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;
109
import static org.assertj.core.api.Assertions.assertThat;
1110

1211
import io.opentelemetry.api.common.Attributes;
@@ -23,7 +22,6 @@
2322
import java.util.Collection;
2423
import java.util.Collections;
2524
import java.util.Map;
26-
import javax.annotation.Nullable;
2725
import org.junit.jupiter.api.Test;
2826
import org.junit.jupiter.api.extension.RegisterExtension;
2927

@@ -33,7 +31,6 @@ class InstrumenterContextTest {
3331
@SuppressWarnings({"unchecked", "deprecation"}) // using deprecated DB_SQL_TABLE
3432
@Test
3533
void testSqlSanitizer() {
36-
Object request = new Object(); // dummy request object
3734
String testQuery = "SELECT name FROM test WHERE id = 1";
3835
SqlClientAttributesGetter<Object, Void> getter =
3936
new SqlClientAttributesGetter<Object, Void>() {
@@ -43,7 +40,6 @@ public String getDbSystem(Object o) {
4340
}
4441

4542
@Override
46-
@Nullable
4743
public String getDbNamespace(Object o) {
4844
return null;
4945
}
@@ -61,12 +57,11 @@ public Collection<String> getRawQueryTexts(Object request) {
6157
cleanup.deferCleanup(InstrumenterContext::reset);
6258

6359
assertThat(InstrumenterContext.get()).isEmpty();
64-
assertThat(spanNameExtractor.extract(request)).isEqualTo("SELECT test");
60+
assertThat(spanNameExtractor.extract(null)).isEqualTo("SELECT test");
6561
// verify that sanitized statement was cached, see SqlStatementSanitizerUtil
6662
assertThat(InstrumenterContext.get()).containsKey("sanitized-sql-map");
6763
Map<String, SqlStatementInfo> sanitizedMap =
68-
(Map<String, SqlStatementInfo>)
69-
requireNonNull(InstrumenterContext.get().get("sanitized-sql-map"));
64+
(Map<String, SqlStatementInfo>) InstrumenterContext.get().get("sanitized-sql-map");
7065
assertThat(sanitizedMap).containsKey(testQuery);
7166

7267
// replace cached sanitization result to verify it is used
@@ -75,7 +70,7 @@ public Collection<String> getRawQueryTexts(Object request) {
7570
SqlStatementInfo.create("SELECT name2 FROM test2 WHERE id = ?", "SELECT", "test2"));
7671
{
7772
AttributesBuilder builder = Attributes.builder();
78-
attributesExtractor.onStart(builder, Context.root(), request);
73+
attributesExtractor.onStart(builder, Context.root(), null);
7974
assertThat(builder.build().get(maybeStable(DbIncubatingAttributes.DB_SQL_TABLE)))
8075
.isEqualTo("test2");
8176
}
@@ -84,7 +79,7 @@ public Collection<String> getRawQueryTexts(Object request) {
8479
sanitizedMap.clear();
8580
{
8681
AttributesBuilder builder = Attributes.builder();
87-
attributesExtractor.onStart(builder, Context.root(), request);
82+
attributesExtractor.onStart(builder, Context.root(), null);
8883
assertThat(builder.build().get(maybeStable(DbIncubatingAttributes.DB_SQL_TABLE)))
8984
.isEqualTo("test");
9085
}

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

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

5252
@Override
53-
@Nullable
5453
public String getUrlFull(Map<String, String> request) {
5554
return request.get("urlFull");
5655
}
5756

5857
@Override
59-
@Nullable
6058
public String getHttpRequestMethod(Map<String, String> request) {
6159
return request.get("method");
6260
}
@@ -68,7 +66,6 @@ public List<String> getHttpRequestHeader(Map<String, String> request, String nam
6866
}
6967

7068
@Override
71-
@Nullable
7269
public Integer getHttpResponseStatusCode(
7370
Map<String, String> request, Map<String, String> response, @Nullable Throwable error) {
7471
String value = response.get("statusCode");

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

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
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;
3029
import static org.assertj.core.api.Assertions.entry;
3130

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

5554
@Override
56-
@Nullable
5755
public String getHttpRequestMethod(Map<String, String> request) {
5856
return request.get("method");
5957
}
6058

6159
@Override
62-
@Nullable
6360
public String getUrlScheme(Map<String, String> request) {
6461
return request.get("urlScheme");
6562
}
@@ -77,7 +74,6 @@ public String getUrlQuery(Map<String, String> request) {
7774
}
7875

7976
@Override
80-
@Nullable
8177
public String getHttpRoute(Map<String, String> request) {
8278
return request.get("route");
8379
}
@@ -89,7 +85,6 @@ public List<String> getHttpRequestHeader(Map<String, String> request, String nam
8985
}
9086

9187
@Override
92-
@Nullable
9388
public Integer getHttpResponseStatusCode(
9489
Map<String, String> request, Map<String, String> response, @Nullable Throwable error) {
9590
String value = response.get("statusCode");
@@ -120,15 +115,15 @@ public String getNetworkType(
120115
@Nullable
121116
@Override
122117
public String getNetworkProtocolName(
123-
Map<String, String> request, @Nullable Map<String, String> response) {
118+
Map<String, String> request, Map<String, String> response) {
124119
return request.get("networkProtocolName");
125120
}
126121

127122
@Nullable
128123
@Override
129124
public String getNetworkProtocolVersion(
130-
Map<String, String> request, @Nullable Map<String, String> response) {
131-
return requireNonNull(request).get("networkProtocolVersion");
125+
Map<String, String> request, Map<String, String> response) {
126+
return request.get("networkProtocolVersion");
132127
}
133128

134129
@Nullable

instrumentation-api/src/test/java/io/opentelemetry/instrumentation/api/semconv/network/NetworkAttributesExtractorInetSocketAddressTest.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,21 +65,16 @@ void fullAddress() {
6565
}
6666

6767
@Test
68-
void minimalAttributes() {
68+
void noAttributes() {
6969
AttributesExtractor<InetSocketAddress, InetSocketAddress> extractor =
7070
NetworkAttributesExtractor.create(new TestNetworkAttributesGetter());
7171

7272
AttributesBuilder startAttributes = Attributes.builder();
73-
InetSocketAddress request = new InetSocketAddress("1.2.3.4", 8080);
74-
extractor.onStart(startAttributes, Context.root(), request);
73+
extractor.onStart(startAttributes, Context.root(), null);
7574
assertThat(startAttributes.build()).isEmpty();
7675

7776
AttributesBuilder endAttributes = Attributes.builder();
78-
extractor.onEnd(endAttributes, Context.root(), request, null, null);
79-
assertThat(endAttributes.build())
80-
.containsOnly(
81-
entry(NETWORK_TYPE, "ipv4"),
82-
entry(NETWORK_LOCAL_ADDRESS, "1.2.3.4"),
83-
entry(NETWORK_LOCAL_PORT, 8080L));
77+
extractor.onEnd(endAttributes, Context.root(), null, null, null);
78+
assertThat(endAttributes.build()).isEmpty();
8479
}
8580
}

0 commit comments

Comments
 (0)