diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt index 0063a5bcc17f..50730c2d8aba 100644 --- a/lucene/CHANGES.txt +++ b/lucene/CHANGES.txt @@ -53,6 +53,7 @@ Bug Fixes --------------------- * GITHUB#13832: Fixed an issue where the DefaultPassageFormatter.format method did not format passages as intended when they were not sorted by startOffset. (Seunghan Jung) +* GITHUB#13884: Remove broken .toArray from Long/CharObjectHashMap entirely. (Pan Guixin) Build --------------------- diff --git a/lucene/core/src/java/org/apache/lucene/internal/hppc/CharObjectHashMap.java b/lucene/core/src/java/org/apache/lucene/internal/hppc/CharObjectHashMap.java index b1fad7017b5d..40b32141f3f2 100644 --- a/lucene/core/src/java/org/apache/lucene/internal/hppc/CharObjectHashMap.java +++ b/lucene/core/src/java/org/apache/lucene/internal/hppc/CharObjectHashMap.java @@ -574,15 +574,6 @@ public Iterator> iterator() { public int size() { return CharObjectHashMap.this.size(); } - - public VType[] toArray() { - VType[] array = (VType[]) new Object[size()]; - int i = 0; - for (ObjectCursor cursor : this) { - array[i++] = cursor.value; - } - return array; - } } /** An iterator over the set of assigned values. */ diff --git a/lucene/core/src/java/org/apache/lucene/internal/hppc/LongObjectHashMap.java b/lucene/core/src/java/org/apache/lucene/internal/hppc/LongObjectHashMap.java index 4bc890b80b1a..5f34625f6750 100644 --- a/lucene/core/src/java/org/apache/lucene/internal/hppc/LongObjectHashMap.java +++ b/lucene/core/src/java/org/apache/lucene/internal/hppc/LongObjectHashMap.java @@ -562,15 +562,6 @@ public Iterator> iterator() { public int size() { return LongObjectHashMap.this.size(); } - - public VType[] toArray() { - VType[] array = (VType[]) new Object[size()]; - int i = 0; - for (ObjectCursor cursor : this) { - array[i++] = cursor.value; - } - return array; - } } /** An iterator over the set of assigned values. */ diff --git a/lucene/core/src/test/org/apache/lucene/internal/hppc/TestCharObjectHashMap.java b/lucene/core/src/test/org/apache/lucene/internal/hppc/TestCharObjectHashMap.java index 4cc036dcfe65..f9a1a259ce83 100644 --- a/lucene/core/src/test/org/apache/lucene/internal/hppc/TestCharObjectHashMap.java +++ b/lucene/core/src/test/org/apache/lucene/internal/hppc/TestCharObjectHashMap.java @@ -17,6 +17,8 @@ package org.apache.lucene.internal.hppc; +import static org.apache.lucene.internal.hppc.TestIntObjectHashMap.toList; + import com.carrotsearch.randomizedtesting.RandomizedTest; import java.util.Arrays; import java.util.HashMap; @@ -24,6 +26,8 @@ import java.util.Random; import java.util.concurrent.atomic.AtomicInteger; import org.apache.lucene.tests.util.LuceneTestCase; +import org.hamcrest.MatcherAssert; +import org.hamcrest.Matchers; import org.junit.After; import org.junit.Test; @@ -66,13 +70,6 @@ private static void assertSortedListEquals(char[] array, char... elements) { assertArrayEquals(elements, array); } - /** Check if the array's content is identical to a given sequence of elements. */ - private static void assertSortedListEquals(Object[] array, Object... elements) { - assertEquals(elements.length, array.length); - Arrays.sort(array); - assertArrayEquals(elements, array); - } - private final int value0 = vcast(0); private final int value1 = vcast(1); private final int value2 = vcast(2); @@ -603,13 +600,15 @@ public void testMapValues() { map.put(key1, value3); map.put(key2, value2); map.put(key3, value1); - assertSortedListEquals(map.values().toArray(), value1, value2, value3); + MatcherAssert.assertThat( + toList(map.values()), Matchers.containsInAnyOrder(value1, value2, value3)); map.clear(); map.put(key1, value1); map.put(key2, value2); map.put(key3, value2); - assertSortedListEquals(map.values().toArray(), value1, value2, value2); + MatcherAssert.assertThat( + toList(map.values()), Matchers.containsInAnyOrder(value1, value2, value2)); } /* */ diff --git a/lucene/core/src/test/org/apache/lucene/internal/hppc/TestIntObjectHashMap.java b/lucene/core/src/test/org/apache/lucene/internal/hppc/TestIntObjectHashMap.java index cc6ac700b54c..4144300ba558 100644 --- a/lucene/core/src/test/org/apache/lucene/internal/hppc/TestIntObjectHashMap.java +++ b/lucene/core/src/test/org/apache/lucene/internal/hppc/TestIntObjectHashMap.java @@ -594,7 +594,7 @@ public void testMapValues() { assertSortedListEquals(toList(map.values()), value1, value2, value2); } - private static List toList(Iterable> values) { + static List toList(Iterable> values) { ArrayList list = new ArrayList<>(); for (var c : values) { list.add(c.value); diff --git a/lucene/core/src/test/org/apache/lucene/internal/hppc/TestLongObjectHashMap.java b/lucene/core/src/test/org/apache/lucene/internal/hppc/TestLongObjectHashMap.java index f5d6176e24b3..df66561197d1 100644 --- a/lucene/core/src/test/org/apache/lucene/internal/hppc/TestLongObjectHashMap.java +++ b/lucene/core/src/test/org/apache/lucene/internal/hppc/TestLongObjectHashMap.java @@ -17,6 +17,8 @@ package org.apache.lucene.internal.hppc; +import static org.apache.lucene.internal.hppc.TestIntObjectHashMap.toList; + import com.carrotsearch.randomizedtesting.RandomizedTest; import java.util.Arrays; import java.util.HashMap; @@ -24,6 +26,8 @@ import java.util.Random; import java.util.concurrent.atomic.AtomicInteger; import org.apache.lucene.tests.util.LuceneTestCase; +import org.hamcrest.MatcherAssert; +import org.hamcrest.Matchers; import org.junit.Test; /** @@ -65,13 +69,6 @@ private static void assertSortedListEquals(long[] array, long... elements) { assertArrayEquals(elements, array); } - /** Check if the array's content is identical to a given sequence of elements. */ - private static void assertSortedListEquals(Object[] array, Object... elements) { - assertEquals(elements.length, array.length); - Arrays.sort(array); - assertArrayEquals(elements, array); - } - private final int value0 = vcast(0); private final int value1 = vcast(1); private final int value2 = vcast(2); @@ -585,13 +582,15 @@ public void testMapValues() { map.put(key1, value3); map.put(key2, value2); map.put(key3, value1); - assertSortedListEquals(map.values().toArray(), value1, value2, value3); + MatcherAssert.assertThat( + toList(map.values()), Matchers.containsInAnyOrder(value1, value2, value3)); map.clear(); map.put(key1, value1); map.put(key2, value2); map.put(key3, value2); - assertSortedListEquals(map.values().toArray(), value1, value2, value2); + MatcherAssert.assertThat( + toList(map.values()), Matchers.containsInAnyOrder(value1, value2, value2)); } /* */