EqualsAvoidNull: enabled

This commit is contained in:
Paul Campbell 2016-09-06 19:01:44 +01:00
parent 322350eda6
commit 5ed44301c8
2 changed files with 18 additions and 5 deletions

View file

@ -126,7 +126,7 @@ You need to include `checkstyle` as the version bundled with the `maven-checksty
* [EmptyPublicCtorInClass](#emptypublicctorinclass) - sevntu - disabled * [EmptyPublicCtorInClass](#emptypublicctorinclass) - sevntu - disabled
* [EmptyStatement](#emptystatement) - checkstyle - enabled * [EmptyStatement](#emptystatement) - checkstyle - enabled
* [EnumValueName](#enumvaluename) - sevntu - enabled * [EnumValueName](#enumvaluename) - sevntu - enabled
* [EqualsAvoidNull](#equalsavoidnull) - checkstyle - disabled * [EqualsAvoidNull](#equalsavoidnull) - checkstyle - enabled
* [EqualsHashCode](#equalshashcode) - checkstyle - enabled * [EqualsHashCode](#equalshashcode) - checkstyle - enabled
* [ExecutableStatementCount](#executablestatementcount) - checkstyle - enabled * [ExecutableStatementCount](#executablestatementcount) - checkstyle - enabled
* [ExplicitInitialization](#explicitinitialization) - checkstyle - enabled * [ExplicitInitialization](#explicitinitialization) - checkstyle - enabled
@ -918,6 +918,22 @@ Invalid:
doSomething();; doSomething();;
```` ````
#### [EqualsAvoidNull](http://checkstyle.sourceforge.net/config_coding.html#EqualsAvoidNull)
Checks that string literals are on the left side in an `equals()` comparison.
Valid:
````
String nullString = null;
"value".equals(nullString);
````
Invalid:
````
String nullString = null;
nullString.equals("value");
````
#### [EqualsHashCode](http://checkstyle.sourceforge.net/config_coding.html#EqualsHashCode) #### [EqualsHashCode](http://checkstyle.sourceforge.net/config_coding.html#EqualsHashCode)
Checks that when a class overrides the `equals()` method, that it also overrides the `hashCode()` method. Checks that when a class overrides the `equals()` method, that it also overrides the `hashCode()` method.
@ -2613,10 +2629,6 @@ These checks are not enabled. Notes are included for each explaining why.
Couldn't get my IDE's (IntelliJ) code style to match. Couldn't get my IDE's (IntelliJ) code style to match.
#### [EqualsAvoidNull](http://checkstyle.sourceforge.net/config_coding.html#EqualsAvoidNull)
> TODO: enable
#### [FinalLocalVariable](http://checkstyle.sourceforge.net/config_coding.html#FinalLocalVariable) #### [FinalLocalVariable](http://checkstyle.sourceforge.net/config_coding.html#FinalLocalVariable)
> TODO: enable > TODO: enable

View file

@ -74,6 +74,7 @@
<module name="EmptyForIteratorPad"/> <!-- empty for loop iterator muse have have no spaces --> <module name="EmptyForIteratorPad"/> <!-- empty for loop iterator muse have have no spaces -->
<module name="EmptyLineSeparator"/> <!-- enforce blank lines after header, fields, constructors, methods, etc --> <module name="EmptyLineSeparator"/> <!-- enforce blank lines after header, fields, constructors, methods, etc -->
<module name="EmptyStatement"/> <!-- prevent standalone ";" semicolons --> <module name="EmptyStatement"/> <!-- prevent standalone ";" semicolons -->
<module name="EqualsAvoidNull"/> <!-- prevents v = null; v.equals("..") -->
<module name="EqualsHashCode"/> <!-- if equals() is overridden then so must hashCode() be --> <module name="EqualsHashCode"/> <!-- if equals() is overridden then so must hashCode() be -->
<module name="ExecutableStatementCount"/> <!-- limit executable statements to 30 per method --> <module name="ExecutableStatementCount"/> <!-- limit executable statements to 30 per method -->
<module name="ExplicitInitialization"/> <!-- avoid initializing a field twice to the same value --> <module name="ExplicitInitialization"/> <!-- avoid initializing a field twice to the same value -->