uber / NullAway

A tool to help eliminate NullPointerExceptions (NPEs) in your Java code with low build-time overhead
MIT License
3.64k stars 294 forks source link

Possible bug in the data flow analysis? #1060

Open mauricioaniche opened 1 week ago

mauricioaniche commented 1 week ago

All, we faced the following NullAway error: [NullAway] unboxing of a @Nullable value in the snippet below. However, as you can see, x can't be null at the point due to the triggered boolean value.

    public double execute(Entity entity, int a, int b) {
        Long x = entity != null ? 123L : null;

        boolean triggered;
        if (a > b) {
            triggered = x != null;
        } else {
            triggered = false;
        }

        double score = 1.0;
        if (triggered) {
            score = score - Utils.function(x); // <-- ERROR HERE!
        }
        return score;
    }

Now that I'm opening up this issue, I believe this can actually be due to #98 (i.e., lack of support for nullability stored in boolean variables). I'll still open up this issue to record that we faced it in a real-world project.

Project reproducing it: https://github.com/mauricioaniche/nullaway-bug.

Library versions:

msridhar commented 1 week ago

Thanks, @mauricioaniche! Yes, I believe this is #98 but I'll leave this one open as well since it's a good example to test on for when we try to fix that one.