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] Improve message of InefficientEmptyStringCheck for String.trim().isEmpty() #1125

krichter722 opened this Issue May 21, 2018 · 0 comments


None yet
2 participants

krichter722 commented May 21, 2018

Affects PMD Version: 6.3.0

Rule: InefficientEmptyStringCheck


public boolean method0(String arg0) {
    return arg0.trim().isEmpty();

produces the message InefficientEmptyStringCheck Priority:3 String.trim().length()==0 is an inefficient way to validate an empty String.. which caused the following misunderstanding on my side: I somehow assumed that there's a difference between String.length()==0 and String.isEmpty() like there is for Collection.size()==0 and Collection.isEmpty() and PMD is confused by the trim in between because of the message. That's not the case and only learned afterwards the String.trim.[length check] is inefficient. It's a rare case, but I'd like to share it together with the suggestion to make the error message say exactly what's written in the code in order to avoid it for anyone else.

Code Sample demonstrating the issue:

see above

Running PMD through: Maven (Plugin version 3.9.0)

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