Skip to content

[java] UselessOperationOnImmutable should detect java.time types #5244

@adangel

Description

@adangel

Is your feature request related to a problem? Please describe.
There are now more immutable types in Java, not just String/BigDecimal/BigInteger.
E.g. the types around java.time.* are all immutable: LocalDate, LocalDateTime, LocalTime, OffsetDate, OffsetDateTime, ZonedDateTime, Instant, Duration, Period... They provide some methods like "plusDays(x)", but won't change the original instance and rather create a new instance.

Maybe there are more immutable types commonly used in Java.

Describe the solution you'd like
The rule UselessOperationOnImmutable should be enhanced to detect further cases. The name of the rule is general enough and can stay the same.

Describe alternatives you've considered
none

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:false-negativePMD doesn't flag a problematic piece of codean:enhancementAn improvement on existing features / rules

    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