Skip to content

Commit a442c18

Browse files
committed
Refine null-safety in the spring-test module
Closes gh-34161
1 parent 7417bd0 commit a442c18

File tree

19 files changed

+47
-29
lines changed

19 files changed

+47
-29
lines changed

spring-test/src/main/java/org/springframework/test/context/jdbc/SqlScriptsTestExecutionListener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ private String[] getScripts(Sql sql, Class<?> testClass, @Nullable Method testMe
410410
* Detect a default SQL script by implementing the algorithm defined in
411411
* {@link Sql#scripts}.
412412
*/
413-
@SuppressWarnings("NullAway")
413+
@SuppressWarnings("NullAway") // Dataflow analysis limitation
414414
private String detectDefaultScript(Class<?> testClass, @Nullable Method testMethod, boolean classLevel) {
415415
Assert.state(classLevel || testMethod != null, "Method-level @Sql requires a testMethod");
416416

spring-test/src/main/java/org/springframework/test/context/junit/jupiter/SpringExtension.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ private static Store getStore(ExtensionContext context) {
373373
* the supplied {@link TestContextManager}.
374374
* @since 6.1
375375
*/
376-
@SuppressWarnings("NullAway")
376+
@SuppressWarnings("NullAway") // org.junit.jupiter.api.extension.ExecutableInvoker is not null marked
377377
private static void registerMethodInvoker(TestContextManager testContextManager, ExtensionContext context) {
378378
testContextManager.getTestContext().setMethodInvoker(context.getExecutableInvoker()::invoke);
379379
}

spring-test/src/main/java/org/springframework/test/context/support/AbstractDirtiesContextTestExecutionListener.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ protected void dirtyContext(TestContext testContext, @Nullable HierarchyMode hie
8484
* @since 4.2
8585
* @see #dirtyContext
8686
*/
87-
@SuppressWarnings("NullAway")
87+
@SuppressWarnings("NullAway") // Dataflow analysis limitation
8888
protected void beforeOrAfterTestMethod(TestContext testContext, MethodMode requiredMethodMode,
8989
ClassMode requiredClassMode) throws Exception {
9090

@@ -136,7 +136,7 @@ else if (logger.isDebugEnabled()) {
136136
* @since 4.2
137137
* @see #dirtyContext
138138
*/
139-
@SuppressWarnings("NullAway")
139+
@SuppressWarnings("NullAway") // Dataflow analysis limitation
140140
protected void beforeOrAfterTestClass(TestContext testContext, ClassMode requiredClassMode) throws Exception {
141141
Assert.notNull(testContext, "TestContext must not be null");
142142
Assert.notNull(requiredClassMode, "requiredClassMode must not be null");

spring-test/src/main/java/org/springframework/test/context/support/ContextLoaderUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ static Map<String, List<ContextConfigurationAttributes>> buildContextHierarchyMa
232232
* @throws IllegalArgumentException if the supplied class is {@code null} or if
233233
* {@code @ContextConfiguration} is not <em>present</em> on the supplied class
234234
*/
235-
@SuppressWarnings("NullAway")
235+
@SuppressWarnings("NullAway") // Dataflow analysis limitation
236236
static List<ContextConfigurationAttributes> resolveContextConfigurationAttributes(Class<?> testClass) {
237237
Assert.notNull(testClass, "Class must not be null");
238238

spring-test/src/main/java/org/springframework/test/context/support/TestPropertySourceUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ else if (!duplicationDetected(currentAttributes, previousAttributes)) {
134134
return mergedAttributes;
135135
}
136136

137-
@SuppressWarnings("NullAway")
137+
@SuppressWarnings("NullAway") // Dataflow analysis limitation
138138
private static boolean duplicationDetected(TestPropertySourceAttributes currentAttributes,
139139
@Nullable TestPropertySourceAttributes previousAttributes) {
140140

spring-test/src/main/java/org/springframework/test/context/transaction/TransactionalTestExecutionListener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ public final int getOrder() {
194194
* @see #getTransactionManager(TestContext, String)
195195
*/
196196
@Override
197-
@SuppressWarnings("NullAway")
197+
@SuppressWarnings("NullAway") // Dataflow analysis limitation
198198
public void beforeTestMethod(final TestContext testContext) throws Exception {
199199
Method testMethod = testContext.getTestMethod();
200200
Class<?> testClass = testContext.getTestClass();

spring-test/src/main/java/org/springframework/test/http/MediaTypeAssert.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ public MediaTypeAssert isCompatibleWith(String mediaType) {
103103
}
104104

105105

106-
@SuppressWarnings("NullAway")
107106
private MediaType parseMediaType(String value) {
108107
try {
109108
return MediaType.parseMediaType(value);

spring-test/src/main/java/org/springframework/test/json/AbstractJsonContentAssert.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ public SELF withCharset(@Nullable Charset charset) {
489489
return (this.actual != null ? this.actual.getJson() : null);
490490
}
491491

492-
@SuppressWarnings("NullAway")
492+
@SuppressWarnings("NullAway") // Dataflow analysis limitation
493493
private String toNonNullJsonString() {
494494
String jsonString = toJsonString();
495495
Assertions.assertThat(jsonString).as("JSON content").isNotNull();

spring-test/src/main/java/org/springframework/test/util/ReflectionTestUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ public static void setField(
173173
* @see ReflectionUtils#setField(Field, Object, Object)
174174
* @see AopTestUtils#getUltimateTargetObject(Object)
175175
*/
176-
@SuppressWarnings("NullAway")
176+
@SuppressWarnings("NullAway") // Dataflow analysis limitation
177177
public static void setField(@Nullable Object targetObject, @Nullable Class<?> targetClass,
178178
@Nullable String name, @Nullable Object value, @Nullable Class<?> type) {
179179

@@ -258,7 +258,7 @@ public static void setField(@Nullable Object targetObject, @Nullable Class<?> ta
258258
* @see ReflectionUtils#getField(Field, Object)
259259
* @see AopTestUtils#getUltimateTargetObject(Object)
260260
*/
261-
@SuppressWarnings("NullAway")
261+
@SuppressWarnings("NullAway") // Dataflow analysis limitation
262262
public static @Nullable Object getField(@Nullable Object targetObject, @Nullable Class<?> targetClass, String name) {
263263
Assert.isTrue(targetObject != null || targetClass != null,
264264
"Either targetObject or targetClass for the field must be specified");

spring-test/src/main/java/org/springframework/test/web/ModelAndViewAssert.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public static void assertModelAttributeValue(ModelAndView mav, String modelName,
109109
* @param mav the ModelAndView to test against (never {@code null})
110110
* @param expectedModel the expected model
111111
*/
112-
@SuppressWarnings("NullAway")
112+
@SuppressWarnings("NullAway") // Dataflow analysis limitation
113113
public static void assertModelAttributeValues(ModelAndView mav, Map<String, Object> expectedModel) {
114114
Map<String, Object> model = mav.getModel();
115115

0 commit comments

Comments
 (0)