LUCENE-2220: Fix stack overflow when calling deprecated CharArraySet.copy()

git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@900152 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Uwe Schindler 2010-01-17 14:38:53 +00:00
parent 7c0cb27edd
commit 98175aacc7
2 changed files with 45 additions and 1 deletions

View File

@ -387,7 +387,7 @@ public class CharArraySet extends AbstractSet<Object> {
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);
}
/**

View File

@ -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<String> stopwords = Arrays.asList(TEST_STOP_WORDS);
List<String> stopwordsUpper = new ArrayList<String>();
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<String> newWords = new ArrayList<String>();
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
*/