Skip to content

Apache Lucene open-source search software

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

Robert Muirc2484192de11
diff --git a/lucene/analysis/common/src/test/org/apache/lucene/collation/TestCollationDocValuesField.java b/lucene/analysis/common/src/test/org/apache/lucene/collation/TestCollationDocValuesField.java
index bbdfe566ab5..c36af197574 100644
--- a/lucene/analysis/common/src/test/org/apache/lucene/collation/TestCollationDocValuesField.java
+++ b/lucene/analysis/common/src/test/org/apache/lucene/collation/TestCollationDocValuesField.java
@@ -120,10 +120,10 @@ public class TestCollationDocValuesField extends LuceneTestCase {
for(int docID=0;docID<is.getIndexReader().maxDoc();docID++) {
StoredDocument doc = is.doc(docID);
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);
boolean luceneAccepts = br.compareTo(startBR) >= 0 && br.compareTo(endBR) <= 0;
- assertEquals(collatorAccepts, luceneAccepts);
+ assertEquals(startPoint + " <= " + s + " <= " + endPoint, collatorAccepts, luceneAccepts);
}
}
}
diff --git a/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java b/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java
index e33ed898a9f..d4e8e6e4786 100644
--- a/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java
+++ b/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java
@@ -2641,6 +2641,7 @@ public abstract class LuceneTestCase extends Assert {
* are impacted by jdk bugs. may not avoid all jdk bugs in tests.
* see https://bugs.openjdk.java.net/browse/JDK-8071862
*/
+ @SuppressForbidden(reason = "dodges JDK-8071862")
public static int collate(Collator collator, String s1, String s2) {
int v1 = collator.compare(s1, s2);
int v2 = collator.getCollationKey(s1).compareTo(collator.getCollationKey(s2));
diff --git a/lucene/tools/forbiddenApis/tests.txt b/lucene/tools/forbiddenApis/tests.txt
index 6e207695935..fbcc0ddd05e 100644
--- a/lucene/tools/forbiddenApis/tests.txt
+++ b/lucene/tools/forbiddenApis/tests.txt
@@ -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
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)