diff --git a/src/java/org/apache/lucene/analysis/CharArraySet.java b/src/java/org/apache/lucene/analysis/CharArraySet.java index 01a39b0c167..6950b4cd861 100644 --- a/src/java/org/apache/lucene/analysis/CharArraySet.java +++ b/src/java/org/apache/lucene/analysis/CharArraySet.java @@ -387,7 +387,7 @@ public class CharArraySet extends AbstractSet { public static CharArraySet copy(final Set set) { if(set == EMPTY_SET) return EMPTY_SET; - return (set instanceof CharArraySet) ? copy((CharArraySet) set) : copy(Version.LUCENE_30, set); + return copy(Version.LUCENE_30, set); } /** diff --git a/src/test/org/apache/lucene/analysis/TestCharArraySet.java b/src/test/org/apache/lucene/analysis/TestCharArraySet.java index 3cb7f9598e7..41e6f09f6f4 100755 --- a/src/test/org/apache/lucene/analysis/TestCharArraySet.java +++ b/src/test/org/apache/lucene/analysis/TestCharArraySet.java @@ -321,6 +321,50 @@ public class TestCharArraySet extends LuceneTestCase { } } + public void testCopyCharArraySetBWCompat() { + CharArraySet setIngoreCase = new CharArraySet(Version.LUCENE_CURRENT, 10, true); + CharArraySet setCaseSensitive = new CharArraySet(Version.LUCENE_CURRENT, 10, false); + + List stopwords = Arrays.asList(TEST_STOP_WORDS); + List stopwordsUpper = new ArrayList(); + for (String string : stopwords) { + stopwordsUpper.add(string.toUpperCase()); + } + setIngoreCase.addAll(Arrays.asList(TEST_STOP_WORDS)); + setIngoreCase.add(Integer.valueOf(1)); + setCaseSensitive.addAll(Arrays.asList(TEST_STOP_WORDS)); + setCaseSensitive.add(Integer.valueOf(1)); + + CharArraySet copy = CharArraySet.copy(setIngoreCase); + CharArraySet copyCaseSens = CharArraySet.copy(setCaseSensitive); + + assertEquals(setIngoreCase.size(), copy.size()); + assertEquals(setCaseSensitive.size(), copy.size()); + + assertTrue(copy.containsAll(stopwords)); + assertTrue(copy.containsAll(stopwordsUpper)); + assertTrue(copyCaseSens.containsAll(stopwords)); + for (String string : stopwordsUpper) { + assertFalse(copyCaseSens.contains(string)); + } + // test adding terms to the copy + List newWords = new ArrayList(); + for (String string : stopwords) { + newWords.add(string+"_1"); + } + copy.addAll(newWords); + + assertTrue(copy.containsAll(stopwords)); + assertTrue(copy.containsAll(stopwordsUpper)); + assertTrue(copy.containsAll(newWords)); + // new added terms are not in the source set + for (String string : newWords) { + assertFalse(setIngoreCase.contains(string)); + assertFalse(setCaseSensitive.contains(string)); + + } + } + /** * Test the static #copy() function with a CharArraySet as a source */