Menu

how do I check with functions using CompareObjectsWithEquals

Help
Yang Li
2018-05-12
2018-05-14
  • Yang Li

    Yang Li - 2018-05-12

    I want to check compare object with == or != in my project,but if I use CompareObjectsWithEquals,
    code like following cannot be reported by PMD:

    if( oldField.getType() == newFiled.getType() ) {.....}

    but if I change the cod to :

    String t1 = oldField.getType();
    String t2 = newField.getType();
    if ( s1 == s2 ) {.....}

    then PMD can report the error to me.
    Did I do something wrong? How could I configure it to check the first code?

     
  • Andreas Dangel

    Andreas Dangel - 2018-05-13

    Hi,
    you are not doing anything wrong. You are running into a current limitation of PMD - we are not yet able to determine the (return) type of method call. If you define local variables first, then we know the type (because you need to explicitly declare the type for the variable declaration) and then we can detect the violation.
    We'll hopefully be able to detect your first example, too, in some time. It needs some more work on the type resolution code.

     
  • Yang Li

    Yang Li - 2018-05-14

    Ok, I got it. Thanks.
    look forward to the future.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.