Skip to content

Commit 6c8ed22

Browse files
committed
Replace NOT operator with explicit false check (#68124)
Part 3. We have an in-house rule to compare explicitly against `false` instead of using the logical not operator (`!`). However, this hasn't historically been enforced, meaning that there are many violations in the source at present. We now have a Checkstyle rule that can detect these cases, but before we can turn it on, we need to fix the existing violations. This is being done over a series of PRs, since there are a lot to fix.
1 parent 78c6d73 commit 6c8ed22

File tree

101 files changed

+196
-192
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+196
-192
lines changed

server/src/internalClusterTest/java/org/elasticsearch/action/admin/HotThreadsIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public void onResponse(NodesHotThreadsResponse nodeHotThreads) {
9797
}
9898
success = true;
9999
} finally {
100-
if (!success) {
100+
if (success == false) {
101101
hasErrors.set(true);
102102
}
103103
latch.countDown();

server/src/internalClusterTest/java/org/elasticsearch/action/bulk/BulkWithUpdatesIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ public void testFailingVersionedUpdatedOnBulk() throws Exception {
529529

530530
int successes = 0;
531531
for (BulkResponse response : responses) {
532-
if (!response.hasFailures()) {
532+
if (response.hasFailures() == false) {
533533
successes++;
534534
}
535535
}

server/src/internalClusterTest/java/org/elasticsearch/action/termvectors/GetTermVectorsIT.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,11 +219,11 @@ public void testSimpleTermVectors() throws IOException {
219219
}
220220

221221
public static String termVectorOptionsToString(FieldType fieldType) {
222-
if (!fieldType.storeTermVectors()) {
222+
if (fieldType.storeTermVectors() == false) {
223223
return "no";
224-
} else if (!fieldType.storeTermVectorOffsets() && !fieldType.storeTermVectorPositions()) {
224+
} else if (fieldType.storeTermVectorOffsets() == false && fieldType.storeTermVectorPositions() == false) {
225225
return "yes";
226-
} else if (fieldType.storeTermVectorOffsets() && !fieldType.storeTermVectorPositions()) {
226+
} else if (fieldType.storeTermVectorOffsets() && fieldType.storeTermVectorPositions() == false) {
227227
return "with_offsets";
228228
} else {
229229
StringBuilder builder = new StringBuilder("with");

server/src/internalClusterTest/java/org/elasticsearch/cluster/allocation/SimpleAllocationIT.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public void testSaneAllocation() {
4949
ClusterState state = client().admin().cluster().prepareState().execute().actionGet().getState();
5050
assertThat(state.getRoutingNodes().unassigned().size(), equalTo(0));
5151
for (RoutingNode node : state.getRoutingNodes()) {
52-
if (!node.isEmpty()) {
52+
if (node.isEmpty() == false) {
5353
assertThat(node.size(), equalTo(2));
5454
}
5555
}
@@ -60,7 +60,7 @@ public void testSaneAllocation() {
6060

6161
assertThat(state.getRoutingNodes().unassigned().size(), equalTo(0));
6262
for (RoutingNode node : state.getRoutingNodes()) {
63-
if (!node.isEmpty()) {
63+
if (node.isEmpty() == false) {
6464
assertThat(node.size(), equalTo(1));
6565
}
6666
}
@@ -79,7 +79,7 @@ public void testSaneAllocation() {
7979

8080
assertThat(state.getRoutingNodes().unassigned().size(), equalTo(0));
8181
for (RoutingNode node : state.getRoutingNodes()) {
82-
if (!node.isEmpty()) {
82+
if (node.isEmpty() == false) {
8383
assertThat(node.size(), equalTo(4));
8484
}
8585
}

server/src/internalClusterTest/java/org/elasticsearch/gateway/RecoverAfterNodesIT.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ public Set<ClusterBlock> waitForNoBlocksOnNode(TimeValue timeout, Client nodeCli
4646
do {
4747
blocks = nodeClient.admin().cluster().prepareState().setLocal(true).execute().actionGet()
4848
.getState().blocks().global(ClusterBlockLevel.METADATA_WRITE);
49-
}
50-
while (!blocks.isEmpty() && (System.currentTimeMillis() - start) < timeout.millis());
49+
} while (blocks.isEmpty() == false && (System.currentTimeMillis() - start) < timeout.millis());
5150
return blocks;
5251
}
5352

server/src/internalClusterTest/java/org/elasticsearch/index/store/CorruptedFileIT.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,14 +210,14 @@ public void afterIndexShardClosed(ShardId sid, @Nullable IndexShard indexShard,
210210
Store store = indexShard.store();
211211
store.incRef();
212212
try {
213-
if (!Lucene.indexExists(store.directory()) && indexShard.state() == IndexShardState.STARTED) {
213+
if (Lucene.indexExists(store.directory()) == false && indexShard.state() == IndexShardState.STARTED) {
214214
return;
215215
}
216216
BytesStreamOutput os = new BytesStreamOutput();
217217
PrintStream out = new PrintStream(os, false, StandardCharsets.UTF_8.name());
218218
CheckIndex.Status status = store.checkIndex(out);
219219
out.flush();
220-
if (!status.clean) {
220+
if (status.clean == false) {
221221
logger.warn("check index [failure]\n{}", os.bytes().utf8ToString());
222222
throw new IOException("index check failure");
223223
}

server/src/internalClusterTest/java/org/elasticsearch/index/store/ExceptionRetryIT.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ public void testRetryDueToExceptionOnNetworkLayer() throws ExecutionException, I
126126
long dupCounter = 0;
127127
boolean found_duplicate_already = false;
128128
for (int i = 0; i < searchResponse.getHits().getHits().length; i++) {
129-
if (!uniqueIds.add(searchResponse.getHits().getHits()[i].getId())) {
130-
if (!found_duplicate_already) {
129+
if (uniqueIds.add(searchResponse.getHits().getHits()[i].getId()) == false) {
130+
if (found_duplicate_already == false) {
131131
SearchResponse dupIdResponse = client().prepareSearch("index").setQuery(termQuery("_id",
132132
searchResponse.getHits().getHits()[i].getId())).setExplain(true).get();
133133
assertThat(dupIdResponse.getHits().getTotalHits().value, greaterThan(1L));

server/src/internalClusterTest/java/org/elasticsearch/indices/analysis/PreBuiltAnalyzerIntegrationIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public void testThatPreBuiltAnalyzersAreNotClosedOnIndexClose() throws Exception
5959
String name = preBuiltAnalyzer.name().toLowerCase(Locale.ROOT);
6060

6161
Version randomVersion = randomVersion(random());
62-
if (!loadedAnalyzers.containsKey(preBuiltAnalyzer)) {
62+
if (loadedAnalyzers.containsKey(preBuiltAnalyzer) == false) {
6363
loadedAnalyzers.put(preBuiltAnalyzer, new ArrayList<Version>());
6464
}
6565
loadedAnalyzers.get(preBuiltAnalyzer).add(randomVersion);

server/src/internalClusterTest/java/org/elasticsearch/indices/memory/breaker/CircuitBreakerServiceIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ public void testLimitsRequestSize() {
383383
// can either fail directly with an exception or the response contains exceptions (depending on client)
384384
try {
385385
BulkResponse response = client.bulk(bulkRequest).actionGet();
386-
if (!response.hasFailures()) {
386+
if (response.hasFailures() == false) {
387387
fail("Should have thrown CircuitBreakingException");
388388
} else {
389389
// each item must have failed with CircuitBreakingException

server/src/internalClusterTest/java/org/elasticsearch/indices/stats/IndexStatsIT.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ public void testThrottleStats() throws Exception {
408408
// make sure we see throttling kicking in:
409409
boolean done = false;
410410
long start = System.currentTimeMillis();
411-
while (!done) {
411+
while (done == false) {
412412
for(int i=0; i<100; i++) {
413413
// Provoke slowish merging by making many unique terms:
414414
StringBuilder sb = new StringBuilder();
@@ -1143,7 +1143,7 @@ public void testConcurrentIndexingAndStatsRequests() throws BrokenBarrierExcepti
11431143
executionFailures.get().add(e);
11441144
latch.countDown();
11451145
}
1146-
while (!stop.get()) {
1146+
while (stop.get() == false) {
11471147
final String id = Integer.toString(idGenerator.incrementAndGet());
11481148
final IndexResponse response =
11491149
client()
@@ -1171,7 +1171,7 @@ public void testConcurrentIndexingAndStatsRequests() throws BrokenBarrierExcepti
11711171
final IndicesStatsRequest request = new IndicesStatsRequest();
11721172
request.all();
11731173
request.indices(new String[0]);
1174-
while (!stop.get()) {
1174+
while (stop.get() == false) {
11751175
try {
11761176
final IndicesStatsResponse response = client().admin().indices().stats(request).get();
11771177
if (response.getFailedShards() > 0) {

0 commit comments

Comments
 (0)