Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nullaway is wrong in reporting #790

Open
nagkumar opened this issue Jul 20, 2023 · 1 comment
Open

Nullaway is wrong in reporting #790

nagkumar opened this issue Jul 20, 2023 · 1 comment

Comments

@nagkumar
Copy link

nagkumar commented Jul 20, 2023

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

@msridhar
Copy link
Collaborator

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.

@nagkumar nagkumar changed the title Nullaway wrongin reporting Nullaway is wrong in reporting Jul 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants