diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 3840454685e..7f731ccb130 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -23,6 +23,9 @@ API Changes
* LUCENE-8014: Similarity.computeSlopFactor() and
Similarity.computePayloadFactor() have been removed (Alan Woodward)
+* LUCENE-8049: IndexWriter.getMergingSegments()'s return type was changed from
+ Collection to Set to more accurately reflect it's nature. (David Smiley)
+
Changes in Runtime Behavior
* LUCENE-7837: Indices that were created before the previous major version
diff --git a/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java b/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java
index 44fb36ec7ad..7f47e42d45d 100644
--- a/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java
+++ b/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java
@@ -2285,9 +2285,9 @@ public class IndexWriter implements Closeable, TwoPhaseCommit, Accountable {
* (which you do when IndexWriter invokes the
* MergePolicy).
*
- *
Do not alter the returned collection! */
- public synchronized Collection getMergingSegments() {
- return mergingSegments;
+ * The Set is unmodifiable. */
+ public synchronized Set getMergingSegments() {
+ return Collections.unmodifiableSet(mergingSegments);
}
/**
diff --git a/lucene/core/src/java/org/apache/lucene/index/LogMergePolicy.java b/lucene/core/src/java/org/apache/lucene/index/LogMergePolicy.java
index 4d0ce51d261..78025634b4a 100644
--- a/lucene/core/src/java/org/apache/lucene/index/LogMergePolicy.java
+++ b/lucene/core/src/java/org/apache/lucene/index/LogMergePolicy.java
@@ -19,10 +19,10 @@ package org.apache.lucene.index;
import java.io.IOException;
import java.util.ArrayList;
-import java.util.Collection;
import java.util.List;
import java.util.Locale;
import java.util.Map;
+import java.util.Set;
/**
* This class implements a {@link MergePolicy} that tries
@@ -462,7 +462,7 @@ public abstract class LogMergePolicy extends MergePolicy {
final List levels = new ArrayList<>(numSegments);
final float norm = (float) Math.log(mergeFactor);
- final Collection mergingSegments = writer.getMergingSegments();
+ final Set mergingSegments = writer.getMergingSegments();
for(int i=0;i merging = writer.getMergingSegments();
- final Collection toBeMerged = new HashSet<>();
+ final Set merging = writer.getMergingSegments();
+ final Set toBeMerged = new HashSet<>();
final List infosSorted = new ArrayList<>(infos.asList());
@@ -519,7 +520,7 @@ public class TieredMergePolicy extends MergePolicy {
List eligible = new ArrayList<>();
boolean forceMergeRunning = false;
- final Collection merging = writer.getMergingSegments();
+ final Set merging = writer.getMergingSegments();
boolean segmentIsOriginal = false;
for(SegmentCommitInfo info : infos) {
final Boolean isOriginal = segmentsToMerge.get(info);
@@ -594,7 +595,7 @@ public class TieredMergePolicy extends MergePolicy {
message("findForcedDeletesMerges infos=" + writer.segString(infos) + " forceMergeDeletesPctAllowed=" + forceMergeDeletesPctAllowed, writer);
}
final List eligible = new ArrayList<>();
- final Collection merging = writer.getMergingSegments();
+ final Set merging = writer.getMergingSegments();
for(SegmentCommitInfo info : infos) {
double pctDeletes = 100.*((double) writer.numDeletedDocs(info))/info.info.maxDoc();
if (pctDeletes > forceMergeDeletesPctAllowed && !merging.contains(info)) {
diff --git a/lucene/test-framework/src/java/org/apache/lucene/index/MockRandomMergePolicy.java b/lucene/test-framework/src/java/org/apache/lucene/index/MockRandomMergePolicy.java
index f9fa601cc32..61efaa2adb4 100644
--- a/lucene/test-framework/src/java/org/apache/lucene/index/MockRandomMergePolicy.java
+++ b/lucene/test-framework/src/java/org/apache/lucene/index/MockRandomMergePolicy.java
@@ -18,11 +18,11 @@ package org.apache.lucene.index;
import java.io.IOException;
import java.util.ArrayList;
-import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Random;
+import java.util.Set;
import org.apache.lucene.util.LuceneTestCase;
import org.apache.lucene.util.TestUtil;
@@ -56,7 +56,7 @@ public class MockRandomMergePolicy extends MergePolicy {
int numSegments = segmentInfos.size();
List segments = new ArrayList<>();
- final Collection merging = writer.getMergingSegments();
+ final Set merging = writer.getMergingSegments();
for(SegmentCommitInfo sipc : segmentInfos) {
if (!merging.contains(sipc)) {