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

[java] False negatives in AssignmentInOperand Rule #3434

Open
Noah0120 opened this issue Jul 30, 2021 · 1 comment
Open

[java] False negatives in AssignmentInOperand Rule #3434

Noah0120 opened this issue Jul 30, 2021 · 1 comment
Assignees
Labels
a:false-negative PMD doesn't flag a problematic piece of code

Comments

@Noah0120
Copy link

Noah0120 commented Jul 30, 2021

Affects PMD Version:
6.36.0+
7.0.0

Rule:
AssignmentInOperand
Please provide the rule name and a link to the rule documentation:
https://pmd.github.io/latest/pmd_rules_java_errorprone.html#assignmentinoperand

Description:
The term Operand means that subexpression of. another expression based on #3429.
Therefore, assignment in another expression should be detected.
However, PMD didn't detect the following five cases:

  1. assignment in a method argument
  2. assignment in a conditional expression
  3. assignment in an array index
  4. assignment in a method caller
  5. assignment in a constructor

Code Sample demonstrating the issue:

class AssignmentInOperand{
        void test(){
        // case1
        keys.contains(k = random.nextLong());
        Character.isJavaIdentifierPart(text.charAt(--j));

        // case2
        addNextStaticMember = ((staticMember.getNextStaticMember() != null) ? true : false) ;
        ((null == theClassMethods) ? (theClassMethods = theClass.getMethods()) : theClassMethods); 

        // case3
        Character.isWhitespace(segment.array[offset++]);
        subPropMatches[i++];

        // case4
        (is = ia.getNext(null)).isPresent();
        (destFile = new File (dest, srcFO.getNameExt ())).exists();

        // case5
        new File(location, projectName = projectNamePrefix + "_" + num).exists();
        }
}

Expected outcome:
These are assignments in another expression.
Therefore, it should be detected.
These are false negatives.

Thank you.

Running PMD through: [CLI]

@Noah0120 Noah0120 added the a:false-negative PMD doesn't flag a problematic piece of code label Jul 30, 2021
@VoidxHoshi
Copy link
Contributor

Well, let me have a try.

@jsotuyod jsotuyod added the needs:pmd7-revalidation The issue hasn't yet been retested vs PMD 7 and may be stale label Mar 17, 2024
@jsotuyod jsotuyod removed the needs:pmd7-revalidation The issue hasn't yet been retested vs PMD 7 and may be stale label Mar 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:false-negative PMD doesn't flag a problematic piece of code
Projects
None yet
Development

No branches or pull requests

3 participants