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] SignatureDeclareThrowsException: false-positive with TestNG annotations #4477

Closed
seanrion opened this issue Apr 17, 2023 · 0 comments · Fixed by #4488
Closed

[java] SignatureDeclareThrowsException: false-positive with TestNG annotations #4477

seanrion opened this issue Apr 17, 2023 · 0 comments · Fixed by #4488
Labels
a:false-positive PMD flags a piece of code that is not problematic
Milestone

Comments

@seanrion
Copy link

Affects PMD Version:7.0.0-rc1

Rule: SignatureDeclareThrowsException

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

Description:
The first code sample uses the annotation org.testng.annotations.AfterClass, and the second one uses org.junit.AfterClass. The analysis results of the two cases should be equivalent because these two annotations are equivalent. However, PMD reports a warning in the first sample and no warnings in the second one. Actually, PMD should not report a warning like the first sample because it is a unit test method and throwing an exception is allowed here.

Code Sample demonstrating the issue:

Case 1

import net.sourceforge.pmd.lang.java.rule.design.signaturedeclarethrowsexception.*;
import org.testng.annotations.AfterClass;
public class TestA extends MyTestCase {
 @AfterClass
  void setUp() throws Exception {} // report a warning
}

Case 2

import net.sourceforge.pmd.lang.java.rule.design.signaturedeclarethrowsexception.*;
import org.junit.AfterClass;
public class TestB extends MyTestCase {
 @AfterClass
  void setUp() throws Exception {} // report no warning
}

Expected outcome: PMD reports a violation at line 5 in the first class, but that's wrong. That's a false positive. PMD will report no violation if PMD sees org.junit.AfterClass.

Running PMD through: CLI

@seanrion seanrion added the a:false-positive PMD flags a piece of code that is not problematic label Apr 17, 2023
@adangel adangel changed the title [java] A false-positive about SignatureDeclareThrowsException [java] SignatureDeclareThrowsException: false-positive with TestNG Apr 22, 2023
@adangel adangel changed the title [java] SignatureDeclareThrowsException: false-positive with TestNG [java] SignatureDeclareThrowsException: false-positive with TestNG annotations Apr 22, 2023
@adangel adangel added this to the 7.0.0 milestone Apr 24, 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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants