Skip to content

[java] NullAssignment - FP with ternay and null as constructor argument #1669

@Vampire

Description

@Vampire

Affects PMD Version: 6.11.0
Rule: NullAssignment
Description:
Should below code really trigger the NullAssignment rule?
Of course I could write "null" instead of null but why should this be worse than wasting a string constant pool place?
Code Sample demonstrating the issue:

throw new IllegalArgumentException(String.format(
        "Unsupported client with class '%s' given",
        (discordClient == null) ? null : discordClient.getClass()));

Running PMD through: Gradle

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions