Skip to content

Commit 0becb4c

Browse files
committed
Restore isNotNull() assertions where removal introduces IntelliJ NPE warnings
The source variables in these spots come from @Nullable-returning methods (or methods IntelliJ infers as @nullable from a 'return null' branch), so removing assertThat(x).isNotNull() before a dereference triggers an IntelliJ 'may produce NullPointerException' warning.
1 parent b56bb6a commit 0becb4c

6 files changed

Lines changed: 25 additions & 0 deletions

File tree

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

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

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

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

187188
InstrumentationScopeInfo scopeInfo = EmittedScopeParser.getScope(fileManager, module);
188189

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

258260
InstrumentationScopeInfo scopeInfo = EmittedScopeParser.getScope(fileManager, module);
259261

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

287290
InstrumentationScopeInfo scopeInfo = EmittedScopeParser.getScope(fileManager, module);
288291

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

321325
InstrumentationScopeInfo scopeInfo = EmittedScopeParser.getScope(fileManager, module);
322326

327+
assertThat(scopeInfo).isNotNull();
323328
assertThat(scopeInfo.getAttributes()).isNotNull();
324329
assertThat(scopeInfo.getAttributes().get(stringKey("string.key"))).isEqualTo("string-value");
325330
assertThat(scopeInfo.getAttributes().get(longKey("int.key"))).isEqualTo(123L);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ void testShouldNormalizeStringQuery(Parameter parameter) {
2727
String normalized = CouchbaseQuerySanitizer.analyze(parameter.query).getQueryText();
2828
// the analytics query ends up with trailing ';' in earlier couchbase version, but no trailing
2929
// ';' in later couchbase version
30+
assertThat(normalized).isNotNull();
3031
assertThat(normalized.replaceFirst(";$", "")).isEqualTo(parameter.expected);
3132
}
3233

instrumentation/jmx-metrics/library/src/test/java/io/opentelemetry/instrumentation/jmx/internal/engine/AttributeExtractorTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,83 +131,95 @@ void testSetup() {
131131
void testByteAttribute() {
132132
BeanAttributeExtractor extractor = BeanAttributeExtractor.fromName("ByteAttribute");
133133
AttributeInfo info = extractor.getAttributeInfo(theServer, objectName);
134+
assertThat(info).isNotNull();
134135
assertThat(info.usesDoubleValues()).isFalse();
135136
}
136137

137138
@Test
138139
void testByteAttributeValue() {
139140
BeanAttributeExtractor extractor = BeanAttributeExtractor.fromName("ByteAttribute");
140141
Number number = extractor.extractNumericalAttribute(theServer, objectName);
142+
assertThat(number).isNotNull();
141143
assertThat(number.longValue()).isEqualTo(10);
142144
}
143145

144146
@Test
145147
void testShortAttribute() {
146148
BeanAttributeExtractor extractor = BeanAttributeExtractor.fromName("ShortAttribute");
147149
AttributeInfo info = extractor.getAttributeInfo(theServer, objectName);
150+
assertThat(info).isNotNull();
148151
assertThat(info.usesDoubleValues()).isFalse();
149152
}
150153

151154
@Test
152155
void testShortAttributeValue() {
153156
BeanAttributeExtractor extractor = BeanAttributeExtractor.fromName("ShortAttribute");
154157
Number number = extractor.extractNumericalAttribute(theServer, objectName);
158+
assertThat(number).isNotNull();
155159
assertThat(number.longValue()).isEqualTo(11);
156160
}
157161

158162
@Test
159163
void testIntAttribute() {
160164
BeanAttributeExtractor extractor = BeanAttributeExtractor.fromName("IntAttribute");
161165
AttributeInfo info = extractor.getAttributeInfo(theServer, objectName);
166+
assertThat(info).isNotNull();
162167
assertThat(info.usesDoubleValues()).isFalse();
163168
}
164169

165170
@Test
166171
void testIntAttributeValue() {
167172
BeanAttributeExtractor extractor = BeanAttributeExtractor.fromName("IntAttribute");
168173
Number number = extractor.extractNumericalAttribute(theServer, objectName);
174+
assertThat(number).isNotNull();
169175
assertThat(number.longValue()).isEqualTo(12);
170176
}
171177

172178
@Test
173179
void testLongAttribute() {
174180
BeanAttributeExtractor extractor = BeanAttributeExtractor.fromName("LongAttribute");
175181
AttributeInfo info = extractor.getAttributeInfo(theServer, objectName);
182+
assertThat(info).isNotNull();
176183
assertThat(info.usesDoubleValues()).isFalse();
177184
}
178185

179186
@Test
180187
void testLongAttributeValue() {
181188
BeanAttributeExtractor extractor = BeanAttributeExtractor.fromName("LongAttribute");
182189
Number number = extractor.extractNumericalAttribute(theServer, objectName);
190+
assertThat(number).isNotNull();
183191
assertThat(number.longValue()).isEqualTo(13);
184192
}
185193

186194
@Test
187195
void testFloatAttribute() {
188196
BeanAttributeExtractor extractor = BeanAttributeExtractor.fromName("FloatAttribute");
189197
AttributeInfo info = extractor.getAttributeInfo(theServer, objectName);
198+
assertThat(info).isNotNull();
190199
assertThat(info.usesDoubleValues()).isTrue();
191200
}
192201

193202
@Test
194203
void testFloatAttributeValue() {
195204
BeanAttributeExtractor extractor = BeanAttributeExtractor.fromName("FloatAttribute");
196205
Number number = extractor.extractNumericalAttribute(theServer, objectName);
206+
assertThat(number).isNotNull();
197207
assertThat(number.doubleValue()).isEqualTo(14.0); // accurate representation
198208
}
199209

200210
@Test
201211
void testDoubleAttribute() {
202212
BeanAttributeExtractor extractor = BeanAttributeExtractor.fromName("DoubleAttribute");
203213
AttributeInfo info = extractor.getAttributeInfo(theServer, objectName);
214+
assertThat(info).isNotNull();
204215
assertThat(info.usesDoubleValues()).isTrue();
205216
}
206217

207218
@Test
208219
void testDoubleAttributeValue() {
209220
BeanAttributeExtractor extractor = BeanAttributeExtractor.fromName("DoubleAttribute");
210221
Number number = extractor.extractNumericalAttribute(theServer, objectName);
222+
assertThat(number).isNotNull();
211223
assertThat(number.doubleValue()).isEqualTo(15.0); // accurate representation
212224
}
213225

@@ -248,6 +260,7 @@ void testNegativeFilter(String attributeName) {
248260

249261
test1.negativeValues = true;
250262
Number rawValue = rawExtractor.extractNumericalAttribute(theServer, objectName);
263+
assertThat(rawValue).isNotNull();
251264
assertThat(rawValue.doubleValue()).isNegative();
252265
assertThat(filteringExtractor.extractNumericalAttribute(theServer, objectName))
253266
.describedAs("negative value should be filtered")

instrumentation/jmx-metrics/library/src/test/java/io/opentelemetry/instrumentation/jmx/internal/engine/UnitConverterTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ private static void testConversion(
4747
Long originalValue, String originalUnit, Double expectedConvertedValue, String targetUnit) {
4848
UnitConverter converter = UnitConverter.getInstance(originalUnit, targetUnit);
4949

50+
assertThat(converter).isNotNull();
5051
Number actualValue = converter.convert(originalValue);
5152

5253
assertThat(expectedConvertedValue).isEqualTo(actualValue);

instrumentation/runtime-telemetry/library/src/testJava17/java/io/opentelemetry/instrumentation/runtimetelemetry/RuntimeTelemetryBuilderTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ void build_WithFeatureEnabled() {
9191
cleanup.deferCleanup(runtimeTelemetry);
9292

9393
var jfrRuntimeMetrics = (JfrConfig.JfrRuntimeMetrics) runtimeTelemetry.getJfrTelemetry();
94+
assertThat(jfrRuntimeMetrics).isNotNull();
9495
assertThat(jfrRuntimeMetrics.getRecordedEventHandlers())
9596
.hasSizeGreaterThan(0)
9697
.allSatisfy(handler -> assertThat(handler.getFeature()).isEqualTo(JfrFeature.LOCK_METRICS));

muzzle/src/test/java/io/opentelemetry/javaagent/tooling/muzzle/ReferenceCollectorTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,11 @@ public void shouldCollectFieldDeclarationReferences() {
198198

199199
ClassRef helperClass = references.get(DeclaredFieldTestClass.Helper.class.getName());
200200
FieldRef superField = findField(helperClass, "superField");
201+
assertThat(superField).isNotNull();
201202
assertThat(superField.isDeclared()).isFalse();
202203

203204
FieldRef field = findField(helperClass, "helperField");
205+
assertThat(field).isNotNull();
204206
assertThat(field.isDeclared()).isTrue();
205207

206208
ClassRef libraryBaseClass =
@@ -447,6 +449,7 @@ private static void assertHelperInterfaceMethod(ClassRef reference, boolean isAb
447449
private static void assertMethod(
448450
ClassRef reference, String methodName, String methodDesc, Flag... flags) {
449451
MethodRef method = findMethod(reference, methodName, methodDesc);
452+
assertThat(method).isNotNull();
450453
assertThat(method.getFlags()).containsExactlyInAnyOrder(flags);
451454
}
452455

@@ -461,6 +464,7 @@ private static MethodRef findMethod(ClassRef reference, String methodName, Strin
461464

462465
private static void assertField(ClassRef reference, String fieldName, Flag... flags) {
463466
FieldRef field = findField(reference, fieldName);
467+
assertThat(field).isNotNull();
464468
assertThat(field.getFlags()).containsExactly(flags);
465469
}
466470

0 commit comments

Comments
 (0)