A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/pmd/pmd/issues/4903 below:

[java] UnnecessaryBoxing, but explicit conversion is necessary · Issue #4903 · pmd/pmd · GitHub

Affects PMD Version: 7.0.0

Rule: UnnecessaryBoxing

Description: PMD reports "Unnecessary explicit conversion from Integer to Long" violation, but removing the explicit conversion will break compilation.

Code Sample demonstrating the issue:

@SuppressWarnings({"PMD.SystemPrintln", "PMD.NoPackage"})
public final class UnnecessaryBoxing {

  private UnnecessaryBoxing() {
  }

  public static void addLong(Long parameter) {
    System.out.println("parameter = " + parameter);
  }

  public static Integer getValue() {
    return 42;
  }

  public static void main(String[] args) {
    addLong(Long.valueOf(getValue())); // PMD complains: "Unnecessary explicit conversion from Integer to Long"
    //addLong(getValue()); // Does not compile: "incompatible types: Integer cannot be converted to Long"
  }
}

Expected outcome:

PMD reports a violation at line 16 (see comment), but that's wrong. That's a false positive.

Running PMD through: Gradle


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4