GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [java] UnnecessaryBoxing: False negative when another overload takes an unrelated reference type · Issue #7134 · pmd/pmd

[java] UnnecessaryBoxing: False negative when another overload takes an unrelated reference type #7134

New issue
Copy link
New issue
Copy link
Open
#7136
Open
[java] UnnecessaryBoxing: False negative when another overload takes an unrelated reference type#7134
#7136
Copy link

Description

@saryn17
saryn17
opened on Oct 2, 2026
Issue body actions

Affects PMD Version: 7.17.0 to 7.28.0

Rule: UnnecessaryBoxing
https://docs.pmd-code.org/latest/pmd_rules_java_codestyle.html#unnecessaryboxing

Description:

#5971 (7.17.0, the fix for #5948) added an overload check to this rule. Its last clause suppresses the warning for any overload with a reference type at the argument position:

pmd/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codestyle/UnnecessaryBoxingRule.java

Lines 255 to 264 in 5c9271c

return overloads.stream()
.filter(overload -> !overload.equals(currentMethod))
.filter(overload -> argIndex < overload.getFormalParameters().size())
.map(overload -> overload.getFormalParameters().get(argIndex))
.anyMatch(overloadParamType ->
// Boxed type is assignable to overload parameter (Object, generic, etc.)
boxedType.isSubtypeOf(overloadParamType)
// Or overload takes reference type while current takes primitive (different conversion paths)
|| overloadParamType.isTypeVariable() || !overloadParamType.isPrimitive() && currentParamType.isPrimitive()
);

currentParamType is always primitive at that point (early return at L243), so the clause does not check whether the boxed argument can be passed to that overload. In the sample, call(String) hides the warning, although call(value) compiles and still calls call(int) (JLS 15.12.2.3).

PMD 7.16.0 reports line 6. 7.17.0 and 7.28.0 don't.

Code Sample demonstrating the issue:

class Example {
    static void call(int value) { }
    static void call(String value) { }

    void test(Integer value) {
        call(value.intValue());
    }
}

JDK calls are affected the same way, e.g. new StringBuilder(n.intValue()) because of StringBuilder(String), and new ArrayList<>(n.intValue()) because of ArrayList(Collection).

Expected outcome:

PMD should report a violation at line 6, but doesn't. This is a false-negative.

Running PMD through: Other (PmdAnalysis API)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.