Skip to content

Commit 4c15f7c

Browse files
JessicaJHeergrunber
authored andcommitted
Add setting for invert equals calls on null
Signed-off-by: Jessica He <[email protected]>
1 parent ccb75b1 commit 4c15f7c

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

document/_java.learnMoreAboutCleanUps.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,4 +147,28 @@ String x = """
147147
System.out.println("abc");
148148
}
149149
}""";
150+
```
151+
152+
### `invertEquals`
153+
154+
Inverts calls to `Object.equals(Object)` and `String.equalsIgnoreCase(String)` to avoid useless null pointer exception.
155+
156+
The caller must be nullable and the parameter must not be nullable.
157+
158+
By avoiding null pointer exceptions, the behavior may change.
159+
160+
For example:
161+
162+
```java
163+
String message = getMessage();
164+
boolean result1 = message.equals("text");
165+
boolean result2 = message.equalsIgnoreCase("text");
166+
```
167+
168+
becomes:
169+
170+
```java
171+
String message = getMessage();
172+
boolean result1 = "text".equals(message);
173+
boolean result2 = "text".equalsIgnoreCase(message);
150174
```

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1008,7 +1008,8 @@
10081008
"qualifyStaticMembers",
10091009
"addOverride",
10101010
"addDeprecated",
1011-
"stringConcatToTextBlock"
1011+
"stringConcatToTextBlock",
1012+
"invertEquals"
10121013
]
10131014
},
10141015
"default": [],

0 commit comments

Comments
 (0)