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] NPE in InvalidSlf4jMessageFormatRule if a logger call with a variable as parameter is not inside a method or constructor #1504

Merged
merged 2 commits into from Dec 7, 2018

Conversation

Projects
None yet
3 participants
@kris-scheibe
Copy link
Contributor

kris-scheibe commented Dec 5, 2018

When checking if the slf4j message is a local variable, InvalidSlf4jMessageFormatRule#expectedArguments expects the logger call to be inside a method or constructor. This fails if the logger call is in an initializer block or a lambda call at class level.

This PR also checks initializer and lambda blocks and adds a null-check if the logger call is somewhere else.

kris-scheibe added some commits Dec 4, 2018

Fix InvalidSlf4jMessageFormatRule fails with a NPE if a logger call w…
…ith a variable as parameter is not inside a method or constructor.

Added test-cases for (static) initializer block and lambda expression block, which also can contain local variable declarations.
@pmd-test

This comment has been minimized.

Copy link

pmd-test commented Dec 5, 2018

1 Message
📖 This changeset introduces 0 new violations and 0 new errors,
removes 0 violations and 0 errors. Full report

Generated by 🚫 Danger

@adangel adangel self-assigned this Dec 7, 2018

@adangel adangel added this to the 6.10.0 milestone Dec 7, 2018

@adangel adangel merged commit 8f1791c into pmd:master Dec 7, 2018

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details

adangel added a commit that referenced this pull request Dec 7, 2018

@adangel

This comment has been minimized.

Copy link
Member

adangel commented Dec 7, 2018

Awesome, thanks!

@kris-scheibe

This comment has been minimized.

Copy link
Contributor

kris-scheibe commented Dec 7, 2018

You're welcome!
@adangel Would it help you guys if I also create an issue for the bug/enhancement?
We've recently started using PMD enforce our coding-standards and fix up a lot of our old code and while I don't hope to find more bugs, I've written/extended a few rules that might be useful to the public.

@adangel

This comment has been minimized.

Copy link
Member

adangel commented Dec 8, 2018

@kris-scheibe For bugs, yes, a issue will be good, since we can then add this easily to the release notes. For an enhancement, it depends: If it changes/enhances a rule, then, yes, we'd like to have a issue, too. For other general enhancements, the pull request is enough.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment