Skip to content

[java] AssignmentInOperand false positive in 7.17.0 for case blocks in switch statements #6092

@kdandoy107255

Description

@kdandoy107255

Affects PMD Version:
7.17.0
Rule:
AssignmentInOperand
Please provide the rule name and a link to the rule documentation:
AssignmentInOperand

Description:
The fix for issue #3434 causes version 7.17.0 to flag assignment in case assignments.

Code Sample demonstrating the issue:

public final class FPTestAssignmentInOperand {
	
	private FPTestAssignmentInOperand() {}
	public static void main(String[] args)
	{
		String a = null;
		String b = null;
		String c = null;
		
	    switch (args[0])
	    {
	    	case "A" -> a = "a";
	    	case "B" -> b = "b";
	    	case "C" -> c = "c";
	    	default -> {/*Do Nothing*/}
	    }
	    System.out.println("A: " + a + ", B: " + b + ", C: " + c);
	}
}

Expected outcome:

PMD reports a violation at lines 12,13, and 14, but that's wrong. That's a false positive.

Running PMD through: Eclipse

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:false-positivePMD flags a piece of code that is not problematic

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions