Skip to content

Configuration option to specify aliases for NullAway warning suppression #1230

@scordio

Description

@scordio

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")?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions