Skip to content

[java] NullAssignment: False positive inside if statement for first assignment #1050

@adangel

Description

@adangel

Affects PMD Version: 6.3.0+, 7.0.0

Rule: NullAssignment

Description:
If there is a variable declaration without initializer, then the first assignment with null is considered already as a NullAssignment. This should be ignored, since it is the first assignment, which should be allowed by the rule.

Code Sample demonstrating the issue:

String key;
if (a) {
	key = "a";
} else if (b) {
	key = "b";
} else {
	key = null;
}

See #629 for the original issue.

Running PMD through: [CLI | Ant | Maven | Gradle | Designer | Other]

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:false-positivePMD flags a piece of code that is not problematicin:data-flowAffects the data flow analysis code

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions