A RetroSearch Logo

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

Search Query:

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

false-positive with TestNG annotations · Issue #4477 · pmd/pmd · GitHub

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


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