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] UnnecessaryBoxing false positive in PMD 7.0.0 in lambda #4924

Open
julius-d opened this issue Apr 4, 2024 · 0 comments · May be fixed by #5019
Open

[java] UnnecessaryBoxing false positive in PMD 7.0.0 in lambda #4924

julius-d opened this issue Apr 4, 2024 · 0 comments · May be fixed by #5019
Assignees
Labels
a:false-positive PMD flags a piece of code that is not problematic
Milestone

Comments

@julius-d
Copy link

julius-d commented Apr 4, 2024

Hi!
I am currently trying to update from 6.55.0 to PMD 7.0.0.

Affects PMD Version: 7.0.0

Rule: UnnecessaryBoxing

Code Sample demonstrating the issue:

import java.util.Optional;

public class Example {

  record Item(int cents) {}

  Long map(Item item) {
    return Optional.ofNullable(item).map(it -> Long.valueOf(it.cents())).orElse(null);
  }
}

Outcome:

PMD Failure: Example:10 Rule:UnnecessaryBoxing Priority:3 
Unnecessary explicit conversion from int to Function<? super Item, ? extends Long>

Running PMD through: maven-pmd-plugin 3.21.2

@julius-d julius-d added the a:false-positive PMD flags a piece of code that is not problematic label Apr 4, 2024
@oowekyala oowekyala changed the title [java] UnnecessaryBoxing false positive in PMD 7.0.0 [java] UnnecessaryBoxing false positive in PMD 7.0.0 in lambda Apr 4, 2024
@oowekyala oowekyala modified the milestone: 7.2.0 May 14, 2024
@oowekyala oowekyala self-assigned this May 14, 2024
oowekyala added a commit to oowekyala/pmd that referenced this issue May 14, 2024
Change a bit the behavior for some test cases.
Previously the rule reported necessary boxing
that could be simplified another way, but that
is an edge case and not worth complexifying
the rule
@oowekyala oowekyala linked a pull request May 14, 2024 that will close this issue
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:false-positive PMD flags a piece of code that is not problematic
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants