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] Fix #4477: A false-positive about SignatureDeclareThrowsException #4488

Merged
merged 2 commits into from
Apr 23, 2023

Conversation

LynnBroe
Copy link
Contributor

@LynnBroe LynnBroe commented Apr 19, 2023

Describe the PR

This PR excludes org.testng.annotations.AfterClass and org.testng.annotations.BeforeClass which cause FP when using in a unit test method and throwing an exception is allowed.

Related issues

Ready?

  • Added unit tests for fixed bug/feature
  • Passing all unit tests
  • Complete build ./mvnw clean verify passes (checked automatically by github actions)
  • Added (in-code) documentation (if needed)

@pmd-test
Copy link

pmd-test commented Apr 19, 2023

1 Message
📖 Compared to master:
This changeset changes 10 violations,
introduces 0 new violations, 0 new errors and 0 new configuration errors,
removes 7 violations, 0 errors and 0 configuration errors.
Full report
Compared to master:
This changeset changes 0 violations,
introduces 0 new violations, 0 new errors and 0 new configuration errors,
removes 3 violations, 0 errors and 0 configuration errors.
Full report

Generated by 🚫 Danger

Comment on lines 82 to 83
|| method.isAnnotationPresent("org.testng.annotations.AfterClass")
|| method.isAnnotationPresent("org.testng.annotations.BeforeClass")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice catch! There are however a bunch of other TestNG annotations that are missing:

@BeforeMethod, @AfterMethod, @BeforeGroup, @AfterGroup, @BeforeTest, @AfterTest, @BeforeSuite and @AfterSuite

To keep this method manageable, we probably want to move all these annotation name Strings (both for junit and testng) to a private static immutable Set<String>, and replace all these method.isAnnotationPresent with something along the lines:

return TEST_CONFIGURATION_ANNOTATIONS.stream().anyMatch(method::isAnnotationPresent)
    || …

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for comment. I will revise it later.

@jsotuyod jsotuyod changed the title Fix #4477 [java] A false-positive about SignatureDeclareThrowsException [java] Fix #4477: A false-positive about SignatureDeclareThrowsException Apr 21, 2023
@jsotuyod
Copy link
Member

Thanks! I'll merge after a couple minor edits.

jsotuyod added a commit that referenced this pull request Apr 23, 2023
@jsotuyod jsotuyod merged commit fa7143b into pmd:master Apr 23, 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
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[java] SignatureDeclareThrowsException: false-positive with TestNG annotations
4 participants