Skip to content

Apache Lucene open-source search software

LUCENE-6435 - applied Adrien Grand's patch to avoid CME on SNBC

Tommaso Teofilia8d08f82479d
diff --git a/lucene/classification/src/java/org/apache/lucene/classification/SimpleNaiveBayesClassifier.java b/lucene/classification/src/java/org/apache/lucene/classification/SimpleNaiveBayesClassifier.java
index 4a80c7c272e..50281bc00b6 100644
--- a/lucene/classification/src/java/org/apache/lucene/classification/SimpleNaiveBayesClassifier.java
+++ b/lucene/classification/src/java/org/apache/lucene/classification/SimpleNaiveBayesClassifier.java
@@ -150,8 +150,10 @@ public class SimpleNaiveBayesClassifier implements Classifier<BytesRef> {
int docsWithClassSize = countDocsWithClass();
while ((next = termsEnum.next()) != null) {
if (next.length > 0) {
+ // We are passing the term to IndexSearcher so we need to make sure it will not change over time
+ next = BytesRef.deepCopyOf(next);
double clVal = calculateLogPrior(next, docsWithClassSize) + calculateLogLikelihood(tokenizedDoc, next, docsWithClassSize);
- dataList.add(new ClassificationResult<>(BytesRef.deepCopyOf(next), clVal));
+ dataList.add(new ClassificationResult<>(next, clVal));
}
}
diff --git a/lucene/classification/src/test/org/apache/lucene/classification/SimpleNaiveBayesClassifierTest.java b/lucene/classification/src/test/org/apache/lucene/classification/SimpleNaiveBayesClassifierTest.java
index 9421917afb6..b8ac8510323 100644
--- a/lucene/classification/src/test/org/apache/lucene/classification/SimpleNaiveBayesClassifierTest.java
+++ b/lucene/classification/src/test/org/apache/lucene/classification/SimpleNaiveBayesClassifierTest.java
@@ -88,7 +88,6 @@ public class SimpleNaiveBayesClassifierTest extends ClassificationTestBase<Bytes
}
}
- @Ignore
@Test
public void testPerformance() throws Exception {
MockAnalyzer analyzer = new MockAnalyzer(random());