Menu

#707 DataflowAnomalyAnalysis false positive DD

New Tickets
open
pmd (543) DFA (8)
PMD
1-Blocker
Bug
2016-12-18
2007-08-03
No

I think this code should not cause DD warning as it is valid. Anyway I get warning on redefinition of 'val' value.

public void test(final boolean param) {
Integer val = null;
if (param) {
val = 1;
}
return val;
}

Discussion

  • Sven Jacob

    Sven Jacob - 2007-08-04

    Logged In: YES
    user_id=1565594
    Originator: NO

    In my opinion val is at first defined with the null reference. In the case that there should be no definition then you would get an ur-anomaly, because the variable may not be defined and is used in the return statement.

    Dont know what would be better.

    Sven.

     
  • Miroslav Šulc

    Miroslav Šulc - 2007-08-04

    Logged In: YES
    user_id=1483986
    Originator: YES

    'val' must be set to null, otherwise the code would not compile (the DU you mentioned).

    IMO there is no other way to write the code when dealing with complex code in the 'if' branch. Up to that, the DD is "valid" only in case 'param' is true.

    So IMO the solution would be to update the rule so it checks whether the redefinition occurs within conditional statement (or maybe within the same level of code, be it top level in the method or a lower level like conditional statements) and if so then do not issue DD.

     
  • Andreas Dangel

    Andreas Dangel - 2016-12-18
    • labels: pmd --> pmd, DFA
    • Module: --> PMD
    • Milestone: --> New Tickets
    • Priority: 5 --> 1-Blocker
    • Type: --> Bug
    • Affects version: -->
    • Ruleset / Rule: -->
     

Log in to post a comment.