A RetroSearch Logo

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

Search Query:

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

[java] UnnecessaryImport FP with static imports of overloaded methods · Issue #4557 · pmd/pmd · GitHub

Affects PMD Version: 7.0.0-rc1/rc2

Rule: UnnecessaryImport

Description:

I've noticed this via #4501 and thought it would be the same as #4432, but it's actually a different case. I've now been able to reproduce it with a minimal example:

Code Sample demonstrating the issue:

File aaa/Truth.java:

package aaa;

public final class Truth {
    public static Object assertThat(Integer actual) {
        return null;
    }

    public static Object assertThat(Long actual) {
        return null;
    }
}

File bbb/Sample.java:

package bbb;

import static aaa.Truth.assertThat; // false positive violation here

public class Sample {
    public static void main(String[] args) {
        assertThat(1); // usage of aaa.Truth::assertThat(Integer)
    }
}

Expected outcome:

PMD reports a violation in bbb/Sample.java at line 3, but that's wrong. That's a false positive.
It's used in line 7.

More info:

This is something with overload resolution: We detect that the two static methods could be used, but we think, this is ambiguous - and that's why we fail the resolution:

if (overloads.size() != 1) {

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