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] MissingStaticMethodInNonInstantiatableClass: false-positive about @Inject #4493

Closed
LynnBroe opened this issue Apr 21, 2023 · 0 comments · Fixed by #4495
Closed

[java] MissingStaticMethodInNonInstantiatableClass: false-positive about @Inject #4493

LynnBroe opened this issue Apr 21, 2023 · 0 comments · Fixed by #4495
Labels
a:false-positive PMD flags a piece of code that is not problematic good first issue A great starting point for new contributors
Milestone

Comments

@LynnBroe
Copy link
Contributor

Affects PMD Version:7.0.0-rc1

Rule: MissingStaticMethodInNonInstantiatableClass

Please provide the rule name and a link to the rule documentation:
https://docs.pmd-code.org/latest/pmd_rules_java_errorprone.html#missingstaticmethodinnoninstantiatableclass

Description:
The first code sample uses the annotation javax.inject.Inject, and the second one uses com.google.inject.Inject. The analysis results of the two cases should be equivalent because these two annotations are equivalent. However, PMD reports a warning in the second sample and no warnings in the first one. Actually, PMD should not report a warning in Case 2 like the Case 1 because it has a injection here.

Code Sample demonstrating the issue:
Case 1

import javax.inject.Inject;
public class Foo {  //  report no warnning
   @Inject
   private Foo() {}
}

public class Bar extends Foo {
   public Bar() {}
}

Case 2

import com.google.inject.Inject;
public class Foo {  // report a warning
   @Inject
   private Foo() {}
}

public class Bar extends Foo {
   public Bar() {}
}

Expected outcome: The analysis results of the two classes should be the same and report no violation.

PMD reports a violation at line 2 in the second case, but that's wrong. That's a false positive. PMD should report no violation if PMD sees com.google.inject.Inject.

Running PMD through: CLI

@LynnBroe LynnBroe added the a:false-positive PMD flags a piece of code that is not problematic label Apr 21, 2023
@jsotuyod jsotuyod added good first issue A great starting point for new contributors has:pr labels Apr 21, 2023
jsotuyod added a commit to Monits/pmd that referenced this issue Apr 22, 2023
@adangel adangel added this to the 7.0.0 milestone Apr 22, 2023
@adangel adangel changed the title [java]false-positive about MissingStaticMethodInNonInstantiatableClass and @Inject [java] MissingStaticMethodInNonInstantiatableClass: false-positive about @Inject Apr 22, 2023
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 good first issue A great starting point for new contributors
Projects
None yet
3 participants