Skip to content

Commit

Permalink
SOLR-15485: discourage Collections.singleton.forEach use (apache#179)
Browse files Browse the repository at this point in the history
  • Loading branch information
cpoerschke authored Jun 25, 2021
1 parent caca827 commit 00e23c1
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 19 deletions.
1 change: 1 addition & 0 deletions gradle/validation/validate-source-patterns.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ class ValidateSourcePatternsTask extends DefaultTask {
(~$/\$$Header\b/$) : 'svn keyword',
(~$/\$$Source\b/$) : 'svn keyword',
(~$/^\uFEFF/$) : 'UTF-8 byte order mark',
(~$/Collections\.singleton.*forEach/$) : 'potentially unnecessary forEach() use with Collections.singleton',
(~$/import java\.lang\.\w+;/$) : 'java.lang import is unnecessary'
]

Expand Down
5 changes: 1 addition & 4 deletions solr/core/src/java/org/apache/solr/core/CoreContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.LinkedHashSet;
import java.util.List;
Expand Down Expand Up @@ -1143,9 +1142,7 @@ public void shutdown() {
} finally {
try {
if (updateShardHandler != null) {
customThreadPool.submit(() -> Collections.singleton(shardHandlerFactory).parallelStream().forEach(c -> {
updateShardHandler.close();
}));
customThreadPool.submit(() -> updateShardHandler.close());
}
} finally {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -414,9 +414,7 @@ protected String getShardsString() {
protected void destroyServers() throws Exception {
ExecutorService customThreadPool = ExecutorUtil.newMDCAwareCachedThreadPool(new SolrNamedThreadFactory("closeThreadPool"));

customThreadPool.submit(() -> Collections.singleton(controlClient).parallelStream().forEach(c -> {
IOUtils.closeQuietly(c);
}));
customThreadPool.submit(() -> IOUtils.closeQuietly(controlClient));

customThreadPool.submit(() -> {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1718,25 +1718,17 @@ public void distribTearDown() throws Exception {
protected void destroyServers() throws Exception {
ExecutorService customThreadPool = ExecutorUtil.newMDCAwareCachedThreadPool(new SolrNamedThreadFactory("closeThreadPool"));

customThreadPool.submit(() -> Collections.singleton(commonCloudSolrClient).parallelStream().forEach(c -> {
IOUtils.closeQuietly(c);
}));
customThreadPool.submit(() -> IOUtils.closeQuietly(commonCloudSolrClient));

customThreadPool.submit(() -> Collections.singleton(controlClient).parallelStream().forEach(c -> {
IOUtils.closeQuietly(c);
}));
customThreadPool.submit(() -> IOUtils.closeQuietly(controlClient));

customThreadPool.submit(() -> coreClients.parallelStream().forEach(c -> {
IOUtils.closeQuietly(c);
}));

customThreadPool.submit(() -> Collections.singletonList(controlClientCloud).parallelStream().forEach(c -> {
IOUtils.closeQuietly(c);
}));
customThreadPool.submit(() -> IOUtils.closeQuietly(controlClientCloud));

customThreadPool.submit(() -> Collections.singletonList(cloudClient).parallelStream().forEach(c -> {
IOUtils.closeQuietly(c);
}));
customThreadPool.submit(() -> IOUtils.closeQuietly(cloudClient));

ExecutorUtil.shutdownAndAwaitTermination(customThreadPool);

Expand Down

0 comments on commit 00e23c1

Please sign in to comment.