You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.
Position literals first in comparisons, if the second argument is null then NullPointerExceptions can be avoided, they will just return false.
Ex:
class Foo {
boolean bar(String x) { //it will throw a nullPointer if x is null
return x.equals("2");
}
boolean bar2(String x) { //this way it will return false even if x is null
return "2".equals(x);
}
}
Position literals first in String comparisons.
Why is this an issue?
Position literals first in comparisons, if the second argument is null then NullPointerExceptions can be avoided, they will just return false.
Ex:
Source
Related code pattern
Enforces literals first in comparisons
Enforces literals to be positioned first in comparisons.
The text was updated successfully, but these errors were encountered: