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

Position literals first in String comparisons #415

Closed
carlwilson opened this issue Mar 26, 2019 · 6 comments
Closed

Position literals first in String comparisons #415

carlwilson opened this issue Mar 26, 2019 · 6 comments
Assignees
Labels
bug A product defect that needs fixing P3 Low priority bugs

Comments

@carlwilson
Copy link
Member

carlwilson commented Mar 26, 2019

There are 38 occurrences of this issue
Why is this an issue?
Since: PMD 3.3

Position literals first in comparisons, if the second argument is null then NullPointerExceptions can be avoided, they will just return false.

Example(s):

class Foo {
  boolean bar(String x) {
    return x.equals("2"); // should be "2".equals(x)
  }
}

Codacy's list of all occurrences of the issue can be found here

@carlwilson carlwilson added bug A product defect that needs fixing P3 Low priority bugs labels Mar 26, 2019
@carlwilson
Copy link
Member Author

carlwilson commented Apr 8, 2019

Hi @nvanderperren I've chosen this as your first issue. It's a pet hate of mine. There's 38 instances of the problem, I'd be happier if you fix them a file at a time and then submit a pull request per file if that's OK? Here's an example in the JHOVE window code:

if (_selectedModule.equals ("")) {
    return null;
}

It should read:

if ("".equals(_selectedModule)) {
    return null;
}

This avoids the code throwing a null pointer exception when _selectedModule is null as the comparison method accounts for this.

Good luck

@nvanderperren
Copy link
Contributor

Thanks @carlwilson, will do!

@nvanderperren
Copy link
Contributor

I think I've solved all 38 occurences

@carlwilson
Copy link
Member Author

I concur, nice work.

@nvanderperren
Copy link
Contributor

yay! 🎉

@carlwilson
Copy link
Member Author

Fixed by #432, #433, #434, #435, #436, #437, #439, #440 and #441

@carlwilson carlwilson removed this from the Hack week tasks milestone Apr 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A product defect that needs fixing P3 Low priority bugs
Projects
None yet
Development

No branches or pull requests

2 participants