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] UnnecessaryFullyQualifiedName false positive with enum constant #1790

Closed
lasselindqvist opened this issue Apr 24, 2019 · 1 comment · Fixed by #2897
Closed

[java] UnnecessaryFullyQualifiedName false positive with enum constant #1790

lasselindqvist opened this issue Apr 24, 2019 · 1 comment · Fixed by #2897
Labels
a:false-positive PMD flags a piece of code that is not problematic
Milestone

Comments

@lasselindqvist
Copy link

lasselindqvist commented Apr 24, 2019

Affects PMD Version: 6.4.0+

Rule:
UnnecessaryFullyQualifiedName

Description:
A false positive in UnnecessaryFullyQualifiedName. If the code has an enum "Float" defined, java.lang.Float cannot be referenced anymore without fully qualifying it. PMD warns about the usage of java.lang.Float.floatToIntBits because it doesn't understand this.

Code Sample demonstrating the issue:

public enum DataType {
  	Float(Float.class) {
		@Override
		public String toString(final Object value) {
			if (value == null) {
				return null;
			}
			final int bits = java.lang.Float.floatToIntBits((java.lang.Float) value); // false-positive
                        return "";
		}
	};
	private Class<?> dataClass;

	private DataType(Class<?> dataClass) {
		this.dataClass = dataClass;
	}

	@Override
	public Class<?> getDataClass() {
		return dataClass;
	}
}

Running PMD through: Maven

Output:
[INFO] PMD Failure: com.DataType:100 Rule:UnnecessaryFullyQualifiedName Priority:4 Unnecessary use of fully qualified name 'java.lang.Float' due to existing implicit import 'java.lang.*'.

Based on release notes and searching issues the false positive was introduced in one of these:
https://github.com/pmd/pmd/pull/1141/files
https://github.com/pmd/pmd/pull/1220/files

@jsotuyod jsotuyod added the a:false-positive PMD flags a piece of code that is not problematic label Apr 27, 2019
oowekyala added a commit to oowekyala/pmd that referenced this issue Nov 2, 2020
@adangel adangel added this to the 7.0.0 milestone Nov 6, 2020
@adangel adangel linked a pull request Nov 6, 2020 that will close this issue
4 tasks
@adangel adangel changed the title [java] Unnecessary use of fully qualified name: false positive [java] Unnecessary use of fully qualified name: false positive with enum constant Nov 6, 2020
@adangel adangel changed the title [java] Unnecessary use of fully qualified name: false positive with enum constant [java] UnnecessaryFullyQualifiedName false positive with enum constant Nov 6, 2020
@adangel
Copy link
Member

adangel commented Nov 6, 2020

Fixed in PMD 7

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.

3 participants