-
Notifications
You must be signed in to change notification settings - Fork 322
Description
I am working on the introduction of JSpecify and NullAway in Spring Batch, and there are many classes that, by design, hold nullable fields, but they are never null in the standard flow of a Spring application.
This is mainly due to the Spring Framework's InitializingBean interface.
The following is a simplified example of a typical Spring Batch class:
import org.jspecify.annotations.Nullable;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.util.Assert;
public class ExampleClass implements InitializingBean {
private @Nullable String name;
// default constructor
public void setName(String name) {
this.name = name;
}
@Override
public void afterPropertiesSet() throws Exception {
Assert.state(name != null, "name cannot be null");
}
public void doSomething() {
// use 'name' without null check in front of it
}
}While performing a name null check before using it in doSomething is cheap in my example, the situation changes when the class state grows and the complexity of doSomething increases.
For this reason, I ended up annotating doSomething with @SuppressWarnings("DataFlowIssue"), but this doesn't seem to be enough for NullAway and I have to do instead:
@SuppressWarnings({ "DataFlowIssue", "NullAway" })Would it be possible to enhance NullAway to ignore whatever is annotated with @SuppressWarnings("DataFlowIssue")?