NullAway icon indicating copy to clipboard operation
NullAway copied to clipboard

Nullaway is wrong in reporting

Open nagkumar opened this issue 2 years ago • 1 comments

for a BDD test like this

package com.tejasoft.edu.calc.date.tests.bdd.ccbr;

import com.tejasoft.edu.calc.date.DateCalc;
import io.cucumber.java.en.Given;
import io.cucumber.java.en.Then;
import io.cucumber.java.en.When;

import java.time.LocalDate;

import static org.junit.jupiter.api.Assertions.assertEquals;

public final class StepsDateCalc
{
    private DateCalc dateCalc;
    private String result;

    @Given("^today is ([0-9]{4}-[0-9]{2}-[0-9]{2})$")
    public void today_is(final LocalDate aNow)
    {
	dateCalc = new DateCalc(aNow);
    }

    @When("^I ask if ([0-9]{4}-[0-9]{2}-[0-9]{2}) is in the past$")
    public void I_ask_if_date_is_in_the_past(final LocalDate aInputDate)
    {
	result = dateCalc.isDateInThePast(aInputDate);
    }

    @Then("^the result should be (yes|no)$")
    public void the_result_should_be(final String aExpectedResult)
    {
	assertEquals(aExpectedResult, result);
    }
}

it reports errors as

experiments\java\edu\src\main\java\com\tejasoft\edu\calc\date\tests\bdd\ccbr\StepsDateCalc.java:14: warning: [NullAway] @NonNull field dateCalc not initialized
    private DateCalc dateCalc;
                     ^
    (see http://t.uber.com/nullaway )
experiments\java\edu\src\main\java\com\tejasoft\edu\calc\date\tests\bdd\ccbr\StepsDateCalc.java:15: warning: [NullAway] @NonNull field result not initialized
    private String result;
                   ^
    (see http://t.uber.com/nullaway )

which is a wrong interpretation as these are the tests that have a lifecycle that way in x methods they are initialized and used in y method etc..

Maybe NullAway should know the framework-related meaning of initialization

nagkumar avatar Jul 20 '23 10:07 nagkumar

I haven't seen test code like this before. It seems like it might be a lot of work to support this framework and its semantics. You might be best off just not running NullAway on these tests.

msridhar avatar Jul 20 '23 17:07 msridhar