You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@boris-petrov thanks for the reports. I don't think we will be able to cut all of them into 6.0.0, but maybe a couple.
The second one is probably the hardest one to tackle (requires DFA), but the others should be easy to fix shall anyone desire to collaborate an easy PR.
Thanks for getting out 6.0.0! Unfortunately it didn't fix any of the false-positive I've mentioned in this issue. Let's leave it open for now as a reference. Thank you so much for your hard work!
I made the following assumptions, since we had some contradictionary statements in the source code:
a TODO, that tells the same like this issue - and unit tests, that tell the opposite.
Null assignment during initialization of a variable is allowed. This includes also a null assignment via a ternary during initialization.
Null assignment after initialization (so a real assignment) should be flagged by this rule. This includes also null assignment via ternary conditions.
Result:
Type type = condition ? something() : null; // <--- this is not flagged
Type foo;
foo = condition ? something() : null; // <--- this is a violation
The second example (if, elseif, else) is not covered by this issue (or the pr #1033). If we decide to implement this, then we should create a new issue. But: Shouldn't the rule flag null assignments as long as there is a possible execution path? In that sense, I see no difference between the if/elseif/else example and ternary conditions.
@adangel I think both are ok. If the variable was final, both cases would be "the first assignment / variable initialization". I find it very confusing that 2 equivalent ways of writing the same would produce different results... it would favor more complex structure / harder to read simply to avoid the warnings.
My view is that initializing a var to null (even if not at declaration) should be ok. Resetting a variable to null is not.
Activity
jsotuyod commentedon Sep 19, 2017
@boris-petrov thanks for the reports. I don't think we will be able to cut all of them into 6.0.0, but maybe a couple.
The second one is probably the hardest one to tackle (requires DFA), but the others should be easy to fix shall anyone desire to collaborate an easy PR.
boris-petrov commentedon Dec 16, 2017
Thanks for getting out
6.0.0! Unfortunately it didn't fix any of the false-positive I've mentioned in this issue. Let's leave it open for now as a reference. Thank you so much for your hard work!adangel commentedon Dec 16, 2017
@boris-petrov Yes, this is expected, since we didn't fix this issue (hence it stayed open - any fixed issue is closed...)
acanda commentedon Feb 6, 2018
Another most likely related variant of this false positive:
adangel commentedon Apr 10, 2018
I made the following assumptions, since we had some contradictionary statements in the source code:
a TODO, that tells the same like this issue - and unit tests, that tell the opposite.
Result:
The second example (if, elseif, else) is not covered by this issue (or the pr #1033). If we decide to implement this, then we should create a new issue. But: Shouldn't the rule flag null assignments as long as there is a possible execution path? In that sense, I see no difference between the if/elseif/else example and ternary conditions.
/cc @jsotuyod
jsotuyod commentedon Apr 10, 2018
@adangel I think both are ok. If the variable was
final, both cases would be "the first assignment / variable initialization". I find it very confusing that 2 equivalent ways of writing the same would produce different results... it would favor more complex structure / harder to read simply to avoid the warnings.My view is that initializing a var to
null(even if not at declaration) should be ok. Resetting a variable tonullis not.[java] NullAssignment false positive