Apache Solr open-source search software
SOLR-16280: simplify for-loops in tests (#929)
Eric Pugh8a441176f81c
diff --git a/solr/core/src/test/org/apache/solr/BasicFunctionalityTest.java b/solr/core/src/test/org/apache/solr/BasicFunctionalityTest.javaindex cac8cdc99fc..ed119a01c92 100644--- a/solr/core/src/test/org/apache/solr/BasicFunctionalityTest.java+++ b/solr/core/src/test/org/apache/solr/BasicFunctionalityTest.java@@ -798,9 +798,9 @@ public class BasicFunctionalityTest extends SolrTestCaseJ4 {assertFalse(d1.getField("id") instanceof LazyDocument.LazyField);values1 = d1.getFields("test_hlt");assertEquals(4, values1.length);- for (int i = 0; i < values1.length; i++) {- assertTrue(values1[i] instanceof LazyDocument.LazyField);- LazyDocument.LazyField f = (LazyDocument.LazyField) values1[i];+ for (IndexableField field : values1) {+ assertTrue(field instanceof LazyDocument.LazyField);+ LazyDocument.LazyField f = (LazyDocument.LazyField) field;assertFalse(f.hasBeenLoaded());}req.close();@@ -825,9 +825,9 @@ public class BasicFunctionalityTest extends SolrTestCaseJ4 {}assertNotNull(values2[0].stringValue()); // actuallize one value- for (int i = 0; i < values2.length; i++) {+ for (IndexableField indexableField : values2) {// now all values for this field should be loaded & cached- LazyDocument.LazyField f = (LazyDocument.LazyField) values2[i];+ LazyDocument.LazyField f = (LazyDocument.LazyField) indexableField;assertTrue(f.hasBeenLoaded());}diff --git a/solr/core/src/test/org/apache/solr/TestDistributedSearch.java b/solr/core/src/test/org/apache/solr/TestDistributedSearch.javaindex 388a8d37655..87bea09de62 100644--- a/solr/core/src/test/org/apache/solr/TestDistributedSearch.java+++ b/solr/core/src/test/org/apache/solr/TestDistributedSearch.java@@ -2004,8 +2004,7 @@ public class TestDistributedSearch extends BaseDistributedSearchTestCase {String shard = entry.getKey();NamedList<?> info = (NamedList<?>) entry.getValue();boolean found = false;- for (int i = 0; i < shardsArr.length; i++) {- String s = shardsArr[i];+ for (String s : shardsArr) {if (shard.contains(s)) {found = true;// make sure that it responded if it's up and the landing node didn't error before sendingdiff --git a/solr/core/src/test/org/apache/solr/cloud/DeleteReplicaTest.java b/solr/core/src/test/org/apache/solr/cloud/DeleteReplicaTest.javaindex a71e71401f9..2dc533da945 100644--- a/solr/core/src/test/org/apache/solr/cloud/DeleteReplicaTest.java+++ b/solr/core/src/test/org/apache/solr/cloud/DeleteReplicaTest.java@@ -537,8 +537,8 @@ public class DeleteReplicaTest extends SolrCloudTestCase {CollectionAdminRequest.deleteReplica(collectionName, "shard1", nonLeader.getName()).process(cluster.getSolrClient());closed.set(true);- for (int i = 0; i < threads.length; i++) {- threads[i].join();+ for (Thread thread : threads) {+ thread.join();}try {diff --git a/solr/core/src/test/org/apache/solr/cloud/DocValuesNotIndexedTest.java b/solr/core/src/test/org/apache/solr/cloud/DocValuesNotIndexedTest.javaindex 388f052c002..74165b6ff74 100644--- a/solr/core/src/test/org/apache/solr/cloud/DocValuesNotIndexedTest.java+++ b/solr/core/src/test/org/apache/solr/cloud/DocValuesNotIndexedTest.java@@ -410,8 +410,7 @@ public class DocValuesNotIndexedTest extends SolrCloudTestCase {int nullCount = 0;int sevenCount = 0;int boolCount = 0;- for (int idx = 0; idx < commands.size(); ++idx) {- GroupCommand fieldCommand = commands.get(idx);+ for (GroupCommand fieldCommand : commands) {for (Group grp : fieldCommand.getValues()) {switch (grp.getResult().size()) {case 7:diff --git a/solr/core/src/test/org/apache/solr/cloud/SystemCollectionCompatTest.java b/solr/core/src/test/org/apache/solr/cloud/SystemCollectionCompatTest.javaindex 2572aeae244..e9c2bf7e012 100644--- a/solr/core/src/test/org/apache/solr/cloud/SystemCollectionCompatTest.java+++ b/solr/core/src/test/org/apache/solr/cloud/SystemCollectionCompatTest.java@@ -182,8 +182,7 @@ public class SystemCollectionCompatTest extends SolrCloudTestCase {log.info("Overseer Status indicates that the overseer is: {}", leader);JettySolrRunner overseerNode = null;List<JettySolrRunner> jettySolrRunners = cluster.getJettySolrRunners();- for (int i = 0; i < jettySolrRunners.size(); i++) {- JettySolrRunner runner = jettySolrRunners.get(i);+ for (JettySolrRunner runner : jettySolrRunners) {if (runner.getNodeName().equals(leader)) {overseerNode = runner;break;diff --git a/solr/core/src/test/org/apache/solr/cloud/TestHashPartitioner.java b/solr/core/src/test/org/apache/solr/cloud/TestHashPartitioner.javaindex 5d14d96c65a..af09e728a00 100644--- a/solr/core/src/test/org/apache/solr/cloud/TestHashPartitioner.java+++ b/solr/core/src/test/org/apache/solr/cloud/TestHashPartitioner.java@@ -217,12 +217,12 @@ public class TestHashPartitioner extends SolrTestCaseJ4 {"!!A/1000","A//8!B///10!C////"};- for (int i = 0; i < ids.length; ++i) {+ for (String id : ids) {try {- Slice targetSlice = coll.getRouter().getTargetSlice(ids[i], null, null, null, coll);+ Slice targetSlice = coll.getRouter().getTargetSlice(id, null, null, null, coll);assertNotNull(targetSlice);} catch (Exception e) {- throw new Exception("Exception routing id '" + ids[i] + "'", e);+ throw new Exception("Exception routing id '" + id + "'", e);}}}diff --git a/solr/core/src/test/org/apache/solr/cloud/TestLockTree.java b/solr/core/src/test/org/apache/solr/cloud/TestLockTree.javaindex 0a9d2bb5d16..33455cc2f0c 100644--- a/solr/core/src/test/org/apache/solr/cloud/TestLockTree.java+++ b/solr/core/src/test/org/apache/solr/cloud/TestLockTree.java@@ -80,8 +80,7 @@ public class TestLockTree extends SolrTestCaseJ4 {List<Pair<CollectionAction, List<String>>> completedOps = new CopyOnWriteArrayList<>();List<Lock> locks = new CopyOnWriteArrayList<>();List<Thread> threads = new ArrayList<>();- for (int i = 0; i < operations.size(); i++) {- Pair<CollectionAction, List<String>> operation = operations.get(i);+ for (Pair<CollectionAction, List<String>> operation : operations) {final Lock lock = session.lock(operation.first(), operation.second());if (lock != null) {Thread thread = new Thread(getRunnable(completedOps, operation, locks, lock));diff --git a/solr/core/src/test/org/apache/solr/cloud/TestStressInPlaceUpdates.java b/solr/core/src/test/org/apache/solr/cloud/TestStressInPlaceUpdates.javaindex 21c7c143c7f..2cd7202f3d1 100644--- a/solr/core/src/test/org/apache/solr/cloud/TestStressInPlaceUpdates.java+++ b/solr/core/src/test/org/apache/solr/cloud/TestStressInPlaceUpdates.java@@ -682,10 +682,11 @@ public class TestStressInPlaceUpdates extends AbstractFullDistribZkTestBase {Slice shard1 = clusterState.getCollection(DEFAULT_COLLECTION).getSlice(SHARD1);leader = shard1.getLeader();- for (int i = 0; i < clients.size(); i++) {+ for (SolrClient client : clients) {String leaderBaseUrl = zkStateReader.getBaseUrlForNodeName(leader.getNodeName());- if (((HttpSolrClient) clients.get(i)).getBaseURL().startsWith(leaderBaseUrl))- return clients.get(i);+ if (((HttpSolrClient) client).getBaseURL().startsWith(leaderBaseUrl)) {+ return client;+ }}return null;diff --git a/solr/core/src/test/org/apache/solr/cloud/api/collections/CollectionsAPIAsyncDistributedZkTest.java b/solr/core/src/test/org/apache/solr/cloud/api/collections/CollectionsAPIAsyncDistributedZkTest.javaindex 7ababd32309..600b9389659 100644--- a/solr/core/src/test/org/apache/solr/cloud/api/collections/CollectionsAPIAsyncDistributedZkTest.java+++ b/solr/core/src/test/org/apache/solr/cloud/api/collections/CollectionsAPIAsyncDistributedZkTest.java@@ -296,8 +296,8 @@ public class CollectionsAPIAsyncDistributedZkTest extends SolrCloudTestCase {assertEquals(1, numSuccess.get());assertEquals(numThreads - 1, numFailure.get());} finally {- for (int i = 0; i < clients.length; i++) {- clients[i].close();+ for (SolrClient client : clients) {+ client.close();}}}diff --git a/solr/core/src/test/org/apache/solr/handler/component/DistributedExpandComponentTest.java b/solr/core/src/test/org/apache/solr/handler/component/DistributedExpandComponentTest.javaindex 095ff3a3ca3..6191d4807fc 100644--- a/solr/core/src/test/org/apache/solr/handler/component/DistributedExpandComponentTest.java+++ b/solr/core/src/test/org/apache/solr/handler/component/DistributedExpandComponentTest.java@@ -498,10 +498,10 @@ public class DistributedExpandComponentTest extends BaseDistributedSearchTestCasprivate void assertExpandGroups(Map<String, SolrDocumentList> expandedResults, String... groups)throws Exception {- for (int i = 0; i < groups.length; i++) {- if (!expandedResults.containsKey(groups[i])) {+ for (String group : groups) {+ if (!expandedResults.containsKey(group)) {throw new Exception(- "Expanded Group Not Found:" + groups[i] + ", Found:" + exportGroups(expandedResults));+ "Expanded Group Not Found:" + group + ", Found:" + exportGroups(expandedResults));}}}diff --git a/solr/core/src/test/org/apache/solr/handler/component/DistributedFacetPivotLongTailTest.java b/solr/core/src/test/org/apache/solr/handler/component/DistributedFacetPivotLongTailTest.javaindex 8315d2c57d4..69060841a6a 100644--- a/solr/core/src/test/org/apache/solr/handler/component/DistributedFacetPivotLongTailTest.java+++ b/solr/core/src/test/org/apache/solr/handler/component/DistributedFacetPivotLongTailTest.java@@ -82,8 +82,8 @@ public class DistributedFacetPivotLongTailTest extends BaseDistributedSearchTestList<PivotField> pivots = null;List<List<PivotField>> shardPivots = new ArrayList<>(clients.size());- for (int i = 0; i < clients.size(); i++) {- shardPivots.add(clients.get(i).query(req).getFacetPivot().get("foo_s,bar_s"));+ for (org.apache.solr.client.solrj.SolrClient client : clients) {+ shardPivots.add(client.query(req).getFacetPivot().get("foo_s,bar_s"));}// top 5 same on all shardsdiff --git a/solr/core/src/test/org/apache/solr/handler/component/StatsComponentTest.java b/solr/core/src/test/org/apache/solr/handler/component/StatsComponentTest.javaindex 1fb6fb634b6..fb18a2ea2ba 100644--- a/solr/core/src/test/org/apache/solr/handler/component/StatsComponentTest.java+++ b/solr/core/src/test/org/apache/solr/handler/component/StatsComponentTest.java@@ -2368,8 +2368,8 @@ public class StatsComponentTest extends SolrTestCaseJ4 {public EnumSet<Stat> next() {EnumSet<Stat> result = EnumSet.noneOf(Stat.class);int[] indexes = wrapped.next();- for (int i = 0; i < indexes.length; i++) {- result.add(all[indexes[i]]);+ for (int index : indexes) {+ result.add(all[index]);}return result;}diff --git a/solr/core/src/test/org/apache/solr/handler/component/TermVectorComponentTest.java b/solr/core/src/test/org/apache/solr/handler/component/TermVectorComponentTest.javaindex cf52416418a..f5d206aa3a2 100644--- a/solr/core/src/test/org/apache/solr/handler/component/TermVectorComponentTest.java+++ b/solr/core/src/test/org/apache/solr/handler/component/TermVectorComponentTest.java@@ -406,16 +406,16 @@ public class TermVectorComponentTest extends SolrTestCaseJ4 {};StringBuilder expected = new StringBuilder("/termVectors/0/test_posofftv/anoth=={");boolean first = true;- for (int i = 0; i < options.length; i++) {+ for (String[] option : options) {final boolean use = random().nextBoolean();if (use) {if (!first) {expected.append(", ");}first = false;- expected.append(options[i][1]);+ expected.append(option[1]);}- list.add(options[i][0]);+ list.add(option[0]);list.add(use ? "true" : "false");}diff --git a/solr/core/src/test/org/apache/solr/handler/export/TestExportWriter.java b/solr/core/src/test/org/apache/solr/handler/export/TestExportWriter.javaindex 25dd2ca0e07..3dd83702f10 100644--- a/solr/core/src/test/org/apache/solr/handler/export/TestExportWriter.java+++ b/solr/core/src/test/org/apache/solr/handler/export/TestExportWriter.java@@ -1235,8 +1235,8 @@ public class TestExportWriter extends SolrTestCaseJ4 {for (int i = 0; i < 100; i++) {boolean found = false;String si = String.valueOf(i);- for (int j = 0; j < docs.size(); j++) {- if (docs.get(j).get("sortabledv_udvas").equals(si)) {+ for (Map<String, Object> doc : docs) {+ if (doc.get("sortabledv_udvas").equals(si)) {found = true;break;}@@ -1362,9 +1362,9 @@ public class TestExportWriter extends SolrTestCaseJ4 {((LinkedHashMap) doclist.get(i)).get("id"),String.valueOf(((HashMap<?, ?>) docs.get(i)).get("id")));- for (int j = 0; j < fieldSorts.length; j++) { // fields ..- String field = fieldSorts[j].getField();- String sort = fieldSorts[j].getSort();+ for (SortFields fieldSort : fieldSorts) { // fields ..+ String field = fieldSort.getField();+ String sort = fieldSort.getSort();String fieldVal1 = String.valueOf(((HashMap) docs.get(i)).get(field)); // 1st docString fieldVal2 = String.valueOf(((HashMap) docs.get(i + 1)).get(field)); // 2nd objif (fieldVal1.equals(fieldVal2)) {diff --git a/solr/core/src/test/org/apache/solr/internal/csv/CSVParserTest.java b/solr/core/src/test/org/apache/solr/internal/csv/CSVParserTest.javaindex d7b5e0bcbd8..361678fae89 100644--- a/solr/core/src/test/org/apache/solr/internal/csv/CSVParserTest.java+++ b/solr/core/src/test/org/apache/solr/internal/csv/CSVParserTest.java@@ -216,9 +216,9 @@ public class CSVParserTest extends TestCase {public void testGetLine() throws IOException {CSVParser parser = new CSVParser(new StringReader(code));String[] tmp = null;- for (int i = 0; i < res.length; i++) {+ for (String[] re : res) {tmp = parser.getLine();- assertTrue(Arrays.equals(res[i], tmp));+ assertTrue(Arrays.equals(re, tmp));}tmp = parser.getLine();assertTrue(tmp == null);@@ -227,10 +227,10 @@ public class CSVParserTest extends TestCase {public void testNextValue() throws IOException {CSVParser parser = new CSVParser(new StringReader(code));String tmp = null;- for (int i = 0; i < res.length; i++) {- for (int j = 0; j < res[i].length; j++) {+ for (String[] re : res) {+ for (String r : re) {tmp = parser.nextValue();- assertEquals(res[i][j], tmp);+ assertEquals(r, tmp);}}tmp = parser.nextValue();@@ -301,9 +301,7 @@ public class CSVParserTest extends TestCase {{""}, // ExcelStrategy does not ignore empty lines{"world", ""}};- String code;- for (int codeIndex = 0; codeIndex < codes.length; codeIndex++) {- code = codes[codeIndex];+ for (String code : codes) {CSVParser parser = new CSVParser(new StringReader(code), CSVStrategy.EXCEL_STRATEGY);String[][] tmp = parser.getAllValues();assertEquals(res.length, tmp.length);@@ -329,9 +327,8 @@ public class CSVParserTest extends TestCase {{"hello", ""}, // CSV Strategy ignores empty lines{"world", ""}};- String code;- for (int codeIndex = 0; codeIndex < codes.length; codeIndex++) {- code = codes[codeIndex];++ for (String code : codes) {CSVParser parser = new CSVParser(new StringReader(code));String[][] tmp = parser.getAllValues();assertEquals(res.length, tmp.length);@@ -351,9 +348,7 @@ public class CSVParserTest extends TestCase {{""}, // ExcelStrategy does not ignore empty lines{""}};- String code;- for (int codeIndex = 0; codeIndex < codes.length; codeIndex++) {- code = codes[codeIndex];+ for (String code : codes) {CSVParser parser = new CSVParser(new StringReader(code), CSVStrategy.EXCEL_STRATEGY);String[][] tmp = parser.getAllValues();assertEquals(res.length, tmp.length);@@ -371,9 +366,7 @@ public class CSVParserTest extends TestCase {String[][] res = {{"hello", ""} // CSV Strategy ignores empty lines};- String code;- for (int codeIndex = 0; codeIndex < codes.length; codeIndex++) {- code = codes[codeIndex];+ for (String code : codes) {CSVParser parser = new CSVParser(new StringReader(code));String[][] tmp = parser.getAllValues();assertEquals(res.length, tmp.length);@@ -579,10 +572,10 @@ public class CSVParserTest extends TestCase {String[][] data = parser.getAllValues();parser = new CSVParser(new StringReader(code));CSVParser parser1 = new CSVParser(new StringReader(code));- for (int i = 0; i < data.length; i++) {- assertTrue(Arrays.equals(parser1.getLine(), data[i]));- for (int j = 0; j < data[i].length; j++) {- assertEquals(parser.nextValue(), data[i][j]);+ for (String[] datum : data) {+ assertTrue(Arrays.equals(parser1.getLine(), datum));+ for (String d : datum) {+ assertEquals(parser.nextValue(), d);}}}diff --git a/solr/core/src/test/org/apache/solr/legacy/TestLegacyNumericUtils.java b/solr/core/src/test/org/apache/solr/legacy/TestLegacyNumericUtils.javaindex 81843565925..155ea24a4e0 100644--- a/solr/core/src/test/org/apache/solr/legacy/TestLegacyNumericUtils.java+++ b/solr/core/src/test/org/apache/solr/legacy/TestLegacyNumericUtils.java@@ -124,15 +124,15 @@ public class TestLegacyNumericUtils extends SolrTestCase {// check the prefix encoding, lower precision should have the difference to original value equal// to the lower removed bitsfinal BytesRefBuilder ref = new BytesRefBuilder();- for (int i = 0; i < vals.length; i++) {+ for (long val : vals) {for (int j = 0; j < 64; j++) {- LegacyNumericUtils.longToPrefixCoded(vals[i], j, ref);+ LegacyNumericUtils.longToPrefixCoded(val, j, ref);long prefixVal = LegacyNumericUtils.prefixCodedToLong(ref.get());long mask = (1L << j) - 1L;assertEquals(- "difference between prefix val and original value for " + vals[i] + " with shift=" + j,- vals[i] & mask,- vals[i] - prefixVal);+ "difference between prefix val and original value for " + val + " with shift=" + j,+ val & mask,+ val - prefixVal);}}}@@ -187,15 +187,15 @@ public class TestLegacyNumericUtils extends SolrTestCase {// check the prefix encoding, lower precision should have the difference to original value equal// to the lower removed bitsfinal BytesRefBuilder ref = new BytesRefBuilder();- for (int i = 0; i < vals.length; i++) {+ for (int val : vals) {for (int j = 0; j < 32; j++) {- LegacyNumericUtils.intToPrefixCoded(vals[i], j, ref);+ LegacyNumericUtils.intToPrefixCoded(val, j, ref);int prefixVal = LegacyNumericUtils.prefixCodedToInt(ref.get());int mask = (1 << j) - 1;assertEquals(- "difference between prefix val and original value for " + vals[i] + " with shift=" + j,- vals[i] & mask,- vals[i] - prefixVal);+ "difference between prefix val and original value for " + val + " with shift=" + j,+ val & mask,+ val - prefixVal);}}}diff --git a/solr/core/src/test/org/apache/solr/schema/TestPointFields.java b/solr/core/src/test/org/apache/solr/schema/TestPointFields.javaindex 70a55534e27..6fb9ff3aa01 100644--- a/solr/core/src/test/org/apache/solr/schema/TestPointFields.java+++ b/solr/core/src/test/org/apache/solr/schema/TestPointFields.java@@ -5289,9 +5289,9 @@ public class TestPointFields extends SolrTestCaseJ4 {SchemaField sf = h.getCore().getLatestSchema().getField(fieldName);assertTrue(sf.getType() instanceof PointField);- for (int i = 0; i < values.length; i++) {+ for (String value : values) {assertQ(- req("q", "{!term f='" + fieldName + "'}" + values[i], "fl", "id," + fieldName),+ req("q", "{!term f='" + fieldName + "'}" + value, "fl", "id," + fieldName),"//*[@numFound='1']");}@@ -5360,9 +5360,9 @@ public class TestPointFields extends SolrTestCaseJ4 {values[(i + 1) % values.length]));}assertU(commit());- for (int i = 0; i < values.length; i++) {+ for (String value : values) {assertQ(- req("q", "{!term f='" + fieldName + "'}" + values[i], "fl", "id," + fieldName),+ req("q", "{!term f='" + fieldName + "'}" + value, "fl", "id," + fieldName),"//*[@numFound='2']");}diff --git a/solr/core/src/test/org/apache/solr/search/QueryEqualityTest.java b/solr/core/src/test/org/apache/solr/search/QueryEqualityTest.javaindex bb0ccf5ff07..1f2ce05ead7 100644--- a/solr/core/src/test/org/apache/solr/search/QueryEqualityTest.java+++ b/solr/core/src/test/org/apache/solr/search/QueryEqualityTest.java@@ -1351,13 +1351,13 @@ public class QueryEqualityTest extends SolrTestCaseJ4 {SolrRequestInfo.clearRequestInfo();}- for (int i = 0; i < queries.length; i++) {- QueryUtils.check(queries[i]);+ for (Query query1 : queries) {+ QueryUtils.check(query1);// yes starting j=0 is redundent, we're making sure every query// is equal to itself, and that the quality checks work regardless// of which caller/callee is used.- for (int j = 0; j < queries.length; j++) {- QueryUtils.checkEqual(queries[i], queries[j]);+ for (Query query2 : queries) {+ QueryUtils.checkEqual(query1, query2);}}}diff --git a/solr/core/src/test/org/apache/solr/search/TestCollapseQParserPlugin.java b/solr/core/src/test/org/apache/solr/search/TestCollapseQParserPlugin.javaindex ba34b465d2c..c6a7ac9cbc5 100644--- a/solr/core/src/test/org/apache/solr/search/TestCollapseQParserPlugin.java+++ b/solr/core/src/test/org/apache/solr/search/TestCollapseQParserPlugin.java@@ -334,8 +334,7 @@ public class TestCollapseQParserPlugin extends SolrTestCaseJ4 {List<Integer> boostedResults = new ArrayList<>();- for (int i = 0; i < resultsArray.length; i++) {- int result = resultsArray[i];+ for (int result : resultsArray) {if (mergeBoost.boost(result)) {boostedResults.add(result);}@@ -343,8 +342,7 @@ public class TestCollapseQParserPlugin extends SolrTestCaseJ4 {List<Integer> controlResults = new ArrayList<>();- for (int i = 0; i < resultsArray.length; i++) {- int result = resultsArray[i];+ for (int result : resultsArray) {if (Arrays.binarySearch(boostedArray, result) > -1) {controlResults.add(result);}diff --git a/solr/core/src/test/org/apache/solr/search/TestFilteredDocIdSet.java b/solr/core/src/test/org/apache/solr/search/TestFilteredDocIdSet.javaindex c38bb77a64e..4517b5b6e1d 100644--- a/solr/core/src/test/org/apache/solr/search/TestFilteredDocIdSet.java+++ b/solr/core/src/test/org/apache/solr/search/TestFilteredDocIdSet.java@@ -19,7 +19,6 @@ package org.apache.solr.search;import java.io.IOException;import java.util.ArrayList;import java.util.Arrays;-import java.util.Iterator;import junit.framework.Assert;import org.apache.lucene.document.Document;import org.apache.lucene.document.Field;@@ -102,9 +101,8 @@ public class TestFilteredDocIdSet extends SolrTestCase {int[] docs = new int[list.size()];int c = 0;- Iterator<Integer> intIter = list.iterator();- while (intIter.hasNext()) {- docs[c++] = intIter.next();+ for (Integer integer : list) {+ docs[c++] = integer.intValue();}int[] answer = new int[] {4, 6, 8};boolean same = Arrays.equals(answer, docs);diff --git a/solr/core/src/test/org/apache/solr/search/TestHashQParserPlugin.java b/solr/core/src/test/org/apache/solr/search/TestHashQParserPlugin.javaindex 5a9bf4ae6c7..4170bfd3ca1 100644--- a/solr/core/src/test/org/apache/solr/search/TestHashQParserPlugin.java+++ b/solr/core/src/test/org/apache/solr/search/TestHashQParserPlugin.java@@ -300,10 +300,7 @@ public class TestHashQParserPlugin extends SolrTestCaseJ4 {private void assertNoOverLap(@SuppressWarnings({"rawtypes"}) Set setA, @SuppressWarnings({"rawtypes"}) Set setB)throws Exception {- @SuppressWarnings({"rawtypes"})- Iterator it = setA.iterator();- while (it.hasNext()) {- Object o = it.next();+ for (Object o : setA) {if (setB.contains(o)) {throw new Exception("Overlapping sets for value:" + o.toString());}diff --git a/solr/core/src/test/org/apache/solr/spelling/IndexBasedSpellCheckerTest.java b/solr/core/src/test/org/apache/solr/spelling/IndexBasedSpellCheckerTest.javaindex 6a57c069af7..9f592ea5450 100644--- a/solr/core/src/test/org/apache/solr/spelling/IndexBasedSpellCheckerTest.java+++ b/solr/core/src/test/org/apache/solr/spelling/IndexBasedSpellCheckerTest.java@@ -319,9 +319,9 @@ public class IndexBasedSpellCheckerTest extends SolrTestCaseJ4 {File altIndexDir = new File(tmpDir, "alternateIdx" + new Date().getTime());Directory dir = newFSDirectory(altIndexDir.toPath());IndexWriter iw = new IndexWriter(dir, new IndexWriterConfig(new WhitespaceAnalyzer()));- for (int i = 0; i < ALT_DOCS.length; i++) {+ for (String alt_doc : ALT_DOCS) {Document doc = new Document();- doc.add(new TextField("title", ALT_DOCS[i], Field.Store.YES));+ doc.add(new TextField("title", alt_doc, Field.Store.YES));iw.addDocument(doc);}iw.forceMerge(1);diff --git a/solr/core/src/test/org/apache/solr/update/TestInPlaceUpdatesDistrib.java b/solr/core/src/test/org/apache/solr/update/TestInPlaceUpdatesDistrib.javaindex ed31ce8dbed..399cefbbe08 100644--- a/solr/core/src/test/org/apache/solr/update/TestInPlaceUpdatesDistrib.java+++ b/solr/core/src/test/org/apache/solr/update/TestInPlaceUpdatesDistrib.java@@ -220,9 +220,10 @@ public class TestInPlaceUpdatesDistrib extends AbstractFullDistribZkTestBase {leader = shard1.getLeader();String leaderBaseUrl = zkStateReader.getBaseUrlForNodeName(leader.getNodeName());- for (int i = 0; i < clients.size(); i++) {- if (((HttpSolrClient) clients.get(i)).getBaseURL().startsWith(leaderBaseUrl))- LEADER = clients.get(i);+ for (SolrClient solrClient : clients) {+ if (((HttpSolrClient) solrClient).getBaseURL().startsWith(leaderBaseUrl)) {+ LEADER = solrClient;+ }}NONLEADERS = new ArrayList<>();@@ -231,9 +232,10 @@ public class TestInPlaceUpdatesDistrib extends AbstractFullDistribZkTestBase {continue;}String baseUrl = zkStateReader.getBaseUrlForNodeName(rep.getNodeName());- for (int i = 0; i < clients.size(); i++) {- if (((HttpSolrClient) clients.get(i)).getBaseURL().startsWith(baseUrl))- NONLEADERS.add(clients.get(i));+ for (SolrClient client : clients) {+ if (((HttpSolrClient) client).getBaseURL().startsWith(baseUrl)) {+ NONLEADERS.add(client);+ }}}@@ -1194,10 +1196,7 @@ public class TestInPlaceUpdatesDistrib extends AbstractFullDistribZkTestBase {log.info("Doc in both replica 0: {}", doc0);log.info("Doc in both replica 1: {}", doc1);// assert both replicas have same effect- for (int i = 0;- i < NONLEADERS.size();- i++) { // 0th is re-ordered replica, 1st is well-ordered replica- SolrClient client = NONLEADERS.get(i);+ for (SolrClient client : NONLEADERS) { // 0th is re-ordered replica, 1st is well-ordered replicaSolrDocument doc = client.getById(String.valueOf(0), params("distrib", "false"));assertNotNull("Client: " + ((HttpSolrClient) client).getBaseURL(), doc);assertEquals(diff --git a/solr/core/src/test/org/apache/solr/update/processor/SignatureUpdateProcessorFactoryTest.java b/solr/core/src/test/org/apache/solr/update/processor/SignatureUpdateProcessorFactoryTest.javaindex 0d7788decf2..fa75b9c7c47 100644--- a/solr/core/src/test/org/apache/solr/update/processor/SignatureUpdateProcessorFactoryTest.java+++ b/solr/core/src/test/org/apache/solr/update/processor/SignatureUpdateProcessorFactoryTest.java@@ -179,20 +179,20 @@ public class SignatureUpdateProcessorFactoryTest extends SolrTestCaseJ4 {threads2[i].setName("testThread2-" + i);}- for (int i = 0; i < threads.length; i++) {- threads[i].start();+ for (Thread thread : threads) {+ thread.start();}- for (int i = 0; i < threads2.length; i++) {- threads2[i].start();+ for (Thread thread2 : threads2) {+ thread2.start();}- for (int i = 0; i < threads.length; i++) {- threads[i].join();+ for (Thread thread : threads) {+ thread.join();}- for (int i = 0; i < threads2.length; i++) {- threads2[i].join();+ for (Thread thread2 : threads2) {+ thread2.join();}SolrCore core = h.getCore();