Skip to content

Commit b522da4

Browse files
committed
Remove redundant assertThat(x).isNotNull() before a dereference
When the next line dereferences x (e.g. x.foo()), an NPE produces an equivalent failure, so the preceding isNotNull() assertion adds no diagnostic value.
1 parent c80068c commit b522da4

26 files changed

Lines changed: 0 additions & 63 deletions

File tree

instrumentation-docs/src/test/java/io/opentelemetry/instrumentation/docs/InstrumentationAnalyzerTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ void testConvertToInstrumentationModule() {
5151
.findFirst()
5252
.orElse(null);
5353

54-
assertThat(log4jModule).isNotNull();
5554
assertThat(log4jModule.getNamespace()).isEqualTo("log4j");
5655
assertThat(log4jModule.getGroup()).isEqualTo("log4j");
5756
assertThat(log4jModule.getSrcPath()).isEqualTo("instrumentation/log4j/log4j-appender-2.17");
@@ -64,7 +63,6 @@ void testConvertToInstrumentationModule() {
6463
.findFirst()
6564
.orElse(null);
6665

67-
assertThat(springModule).isNotNull();
6866
assertThat(springModule.getNamespace()).isEqualTo("spring");
6967
assertThat(springModule.getGroup()).isEqualTo("spring");
7068
assertThat(springModule.getSrcPath()).isEqualTo("instrumentation/spring/spring-web");

instrumentation-docs/src/test/java/io/opentelemetry/instrumentation/docs/parsers/EmittedScopeParserTest.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,6 @@ void testGetScopeWithMatchingName(@TempDir Path tempDir) throws IOException {
160160

161161
InstrumentationScopeInfo scopeInfo = EmittedScopeParser.getScope(fileManager, module);
162162

163-
assertThat(scopeInfo).isNotNull();
164163
assertThat(scopeInfo.getName()).isEqualTo("io.opentelemetry.test-lib-1.0");
165164
assertThat(scopeInfo.getSchemaUrl()).isNull();
166165
}
@@ -187,7 +186,6 @@ void testGetScopeWithSchemaUrl(@TempDir Path tempDir) throws IOException {
187186

188187
InstrumentationScopeInfo scopeInfo = EmittedScopeParser.getScope(fileManager, module);
189188

190-
assertThat(scopeInfo).isNotNull();
191189
assertThat(scopeInfo.getName()).isEqualTo("io.opentelemetry.spring-web-6.0");
192190
assertThat(scopeInfo.getSchemaUrl()).isEqualTo("https://opentelemetry.io/schemas/1.21.0");
193191
}
@@ -259,7 +257,6 @@ void testGetScopeMultipleScopesOneMatches(@TempDir Path tempDir) throws IOExcept
259257

260258
InstrumentationScopeInfo scopeInfo = EmittedScopeParser.getScope(fileManager, module);
261259

262-
assertThat(scopeInfo).isNotNull();
263260
assertThat(scopeInfo.getName()).isEqualTo("io.opentelemetry.hibernate-6.0");
264261
assertThat(scopeInfo.getSchemaUrl()).isEqualTo("https://opentelemetry.io/schemas/1.21.0");
265262
}
@@ -289,7 +286,6 @@ void testGetScopeWithStringAttributes(@TempDir Path tempDir) throws IOException
289286

290287
InstrumentationScopeInfo scopeInfo = EmittedScopeParser.getScope(fileManager, module);
291288

292-
assertThat(scopeInfo).isNotNull();
293289
assertThat(scopeInfo.getName()).isEqualTo("io.opentelemetry.jdbc");
294290
assertThat(scopeInfo.getAttributes()).isNotNull();
295291
assertThat(scopeInfo.getAttributes().get(stringKey("test.key"))).isEqualTo("test-value");
@@ -324,7 +320,6 @@ void testGetScopeWithMixedTypeAttributes(@TempDir Path tempDir) throws IOExcepti
324320

325321
InstrumentationScopeInfo scopeInfo = EmittedScopeParser.getScope(fileManager, module);
326322

327-
assertThat(scopeInfo).isNotNull();
328323
assertThat(scopeInfo.getAttributes()).isNotNull();
329324
assertThat(scopeInfo.getAttributes().get(stringKey("string.key"))).isEqualTo("string-value");
330325
assertThat(scopeInfo.getAttributes().get(longKey("int.key"))).isEqualTo(123L);

instrumentation/aws-lambda/aws-lambda-events-common-2.2/library/src/test/java/io/opentelemetry/instrumentation/awslambdaevents/common/v2_2/internal/SerializationUtilTest.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,6 @@ private static Map<Class<?>, String> buildEventExamples() {
194194
}
195195

196196
private static void assertScheduledEvent(ScheduledEvent event) {
197-
assertThat(event).isNotNull();
198197
assertThat(event.getSource()).isEqualTo("aws.events");
199198
assertThat(event.getDetailType()).isEqualTo("Scheduled Event");
200199
assertThat(event.getAccount()).isEqualTo("123456789012");
@@ -205,7 +204,6 @@ private static void assertScheduledEvent(ScheduledEvent event) {
205204
}
206205

207206
private static void assertKinesisEvent(KinesisEvent event) {
208-
assertThat(event).isNotNull();
209207
assertThat(event.getRecords()).isNotNull();
210208
assertThat(event.getRecords()).hasSize(2);
211209
KinesisEvent.KinesisEventRecord record = event.getRecords().get(0);
@@ -223,7 +221,6 @@ private static void assertKinesisEvent(KinesisEvent event) {
223221
}
224222

225223
private static void assertSqsEvent(SQSEvent event) {
226-
assertThat(event).isNotNull();
227224
assertThat(event.getRecords()).isNotNull();
228225
assertThat(event.getRecords()).hasSize(2);
229226
SQSEvent.SQSMessage record = event.getRecords().get(0);
@@ -236,7 +233,6 @@ private static void assertSqsEvent(SQSEvent event) {
236233
}
237234

238235
private static void assertS3Event(S3Event event) {
239-
assertThat(event).isNotNull();
240236
assertThat(event.getRecords()).isNotNull();
241237
assertThat(event.getRecords()).hasSize(1);
242238
S3EventNotification.S3EventNotificationRecord record = event.getRecords().get(0);
@@ -249,7 +245,6 @@ private static void assertS3Event(S3Event event) {
249245
}
250246

251247
private static void assertSnsEvent(SNSEvent event) {
252-
assertThat(event).isNotNull();
253248
assertThat(event.getRecords()).isNotNull();
254249
assertThat(event.getRecords()).hasSize(1);
255250
SNSEvent.SNSRecord record = event.getRecords().get(0);

instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2ClientCoreTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,9 @@ void prepTest() {
125125
}
126126

127127
private void validateOperationResponse(String operation, Object response) {
128-
assertThat(response).isNotNull();
129128
assertThat(response.getClass().getSimpleName()).startsWith(operation);
130129

131130
RecordedRequest request = server.takeRequest();
132-
assertThat(request).isNotNull();
133131
assertThat(request.request().headers().get("X-Amzn-Trace-Id")).isNotNull();
134132
assertThat(request.request().headers().get("traceparent")).isNull();
135133

instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2ClientTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,6 @@ private void clientAssertions(
291291
assertThat(response).isNotNull();
292292

293293
RecordedRequest request = server.takeRequest();
294-
assertThat(request).isNotNull();
295294
assertThat(request.request().headers().get("X-Amzn-Trace-Id")).isNotNull();
296295
assertThat(request.request().headers().get("traceparent")).isNull();
297296

instrumentation/clickhouse/clickhouse-client-v1-0.5/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/clickhouse/clientv1/v0_5/ClickHouseClientV1Test.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,6 @@ void testAsyncExecuteQuery() throws Exception {
299299
.execute();
300300

301301
ClickHouseResponse result = response.get();
302-
assertThat(result).isNotNull();
303302
result.close();
304303

305304
testing.waitAndAssertTraces(

instrumentation/couchbase/couchbase-common-2.0/javaagent-unit-tests/src/test/java/io/opentelemetry/javaagent/instrumentation/couchbase/common/v2_0/CouchbaseQuerySanitizerTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ class CouchbaseQuerySanitizerTest {
2525
@MethodSource("providesArguments")
2626
void testShouldNormalizeStringQuery(Parameter parameter) {
2727
String normalized = CouchbaseQuerySanitizer.analyze(parameter.query).getQueryText();
28-
assertThat(normalized).isNotNull();
2928
// the analytics query ends up with trailing ';' in earlier couchbase version, but no trailing
3029
// ';' in later couchbase version
3130
assertThat(normalized.replaceFirst(";$", "")).isEqualTo(parameter.expected);

instrumentation/iceberg-1.8/testing/src/main/java/io/opentelemetry/instrumentation/iceberg/v1_8/AbstractIcebergTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ void testCreateTelemetry() throws IOException {
8484
scan = configure(scan);
8585

8686
try (CloseableIterable<FileScanTask> tasks = scan.planFiles()) {
87-
assertThat(tasks).isNotNull();
8887
assertThat(tasks.iterator()).isNotNull();
8988
}
9089

instrumentation/internal/internal-class-loader/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/internal/classloader/ClassLoadingTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ void testDelegatesToBootstrapClassLoaderForAgentClasses() throws ClassNotFoundEx
2020
Class.forName(
2121
"io.opentelemetry.javaagent.bootstrap.Java8BytecodeBridge", false, classLoader);
2222

23-
assertThat(clazz).isNotNull();
2423
assertThat(clazz.getClassLoader()).isNull();
2524
}
2625

@@ -30,7 +29,6 @@ void testDelegatesToBootstrapClassLoaderForAgentClassesTwoArguments()
3029
NonDelegatingUrlClassLoader classLoader = new NonDelegatingUrlClassLoader();
3130
Class<?> clazz =
3231
classLoader.loadClass("io.opentelemetry.javaagent.bootstrap.Java8BytecodeBridge", false);
33-
assertThat(clazz).isNotNull();
3432
assertThat(clazz.getClassLoader()).isNull();
3533
}
3634

instrumentation/internal/internal-class-loader/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/internal/classloader/JbossClassloadingTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ void testDelegatesToBootstrapClassLoaderForAgentClasses()
3939
Class.forName(
4040
"io.opentelemetry.javaagent.bootstrap.Java8BytecodeBridge", false, classLoader);
4141

42-
assertThat(clazz).isNotNull();
4342
assertThat(clazz.getClassLoader()).isNull();
4443
}
4544
}

0 commit comments

Comments
 (0)