LUCENE-6206: don't fail test if it encounters jdk bug, ban Collator.compare in tests so this never pops again

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1700261 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Muir 2015-08-31 15:10:15 +00:00
parent 431ed53d46
commit c2484192de
3 changed files with 7 additions and 2 deletions

View File

@ -120,10 +120,10 @@ public class TestCollationDocValuesField extends LuceneTestCase {
for(int docID=0;docID<is.getIndexReader().maxDoc();docID++) { for(int docID=0;docID<is.getIndexReader().maxDoc();docID++) {
StoredDocument doc = is.doc(docID); StoredDocument doc = is.doc(docID);
String s = doc.getField("field").stringValue(); String s = doc.getField("field").stringValue();
boolean collatorAccepts = collator.compare(s, startPoint) >= 0 && collator.compare(s, endPoint) <= 0; boolean collatorAccepts = collate(collator, s, startPoint) >= 0 && collate(collator, s, endPoint) <= 0;
BytesRef br = dvs.get(docID); BytesRef br = dvs.get(docID);
boolean luceneAccepts = br.compareTo(startBR) >= 0 && br.compareTo(endBR) <= 0; boolean luceneAccepts = br.compareTo(startBR) >= 0 && br.compareTo(endBR) <= 0;
assertEquals(collatorAccepts, luceneAccepts); assertEquals(startPoint + " <= " + s + " <= " + endPoint, collatorAccepts, luceneAccepts);
} }
} }
} }

View File

@ -2641,6 +2641,7 @@ public abstract class LuceneTestCase extends Assert {
* are impacted by jdk bugs. may not avoid all jdk bugs in tests. * are impacted by jdk bugs. may not avoid all jdk bugs in tests.
* see https://bugs.openjdk.java.net/browse/JDK-8071862 * see https://bugs.openjdk.java.net/browse/JDK-8071862
*/ */
@SuppressForbidden(reason = "dodges JDK-8071862")
public static int collate(Collator collator, String s1, String s2) { public static int collate(Collator collator, String s1, String s2) {
int v1 = collator.compare(s1, s2); int v1 = collator.compare(s1, s2);
int v2 = collator.getCollationKey(s1).compareTo(collator.getCollationKey(s2)); int v2 = collator.getCollationKey(s1).compareTo(collator.getCollationKey(s2));

View File

@ -23,3 +23,7 @@ java.lang.Math#random() @ Use RandomizedRunner's random().nextDouble() instead
#java.lang.System#nanoTime() @ Don't depend on wall clock times #java.lang.System#nanoTime() @ Don't depend on wall clock times
com.carrotsearch.randomizedtesting.annotations.Seed @ Don't commit hardcoded seeds com.carrotsearch.randomizedtesting.annotations.Seed @ Don't commit hardcoded seeds
@defaultMessage Use LuceneTestCase.collate instead, which can avoid JDK-8071862
java.text.Collator#compare(java.lang.Object,java.lang.Object)
java.text.Collator#compare(java.lang.String,java.lang.String)