Skip to content

Apache Lucene open-source search software

LUCENE-5710: don't swallow innner immense term exception

Michael McCandless753e0a2592bd
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 3a1743438c7..d7866cf8922 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -231,6 +231,10 @@ Bug fixes
* LUCENE-5704: Fix compilation error with Java 8u20. (Uwe Schindler)
+* LUCENE-5710: Include the inner exception as the cause and in the
+ exception message when an immense term is hit during indexing (Lee
+ Hinman via Mike McCandless)
+
Test Framework
* LUCENE-5622: Fail tests if they print over the given limit of bytes to
diff --git a/lucene/core/src/java/org/apache/lucene/index/DefaultIndexingChain.java b/lucene/core/src/java/org/apache/lucene/index/DefaultIndexingChain.java
index 89f54420898..2a2454e5a7c 100644
--- a/lucene/core/src/java/org/apache/lucene/index/DefaultIndexingChain.java
+++ b/lucene/core/src/java/org/apache/lucene/index/DefaultIndexingChain.java
@@ -648,12 +648,12 @@ final class DefaultIndexingChain extends DocConsumer {
byte[] prefix = new byte[30];
BytesRef bigTerm = invertState.termAttribute.getBytesRef();
System.arraycopy(bigTerm.bytes, bigTerm.offset, prefix, 0, 30);
- String msg = "Document contains at least one immense term in field=\"" + fieldInfo.name + "\" (whose UTF8 encoding is longer than the max length " + DocumentsWriterPerThread.MAX_TERM_LENGTH_UTF8 + "), all of which were skipped. Please correct the analyzer to not produce such terms. The prefix of the first immense term is: '" + Arrays.toString(prefix) + "...'";
+ String msg = "Document contains at least one immense term in field=\"" + fieldInfo.name + "\" (whose UTF8 encoding is longer than the max length " + DocumentsWriterPerThread.MAX_TERM_LENGTH_UTF8 + "), all of which were skipped. Please correct the analyzer to not produce such terms. The prefix of the first immense term is: '" + Arrays.toString(prefix) + "...', original message: " + e.getMessage();
if (docState.infoStream.isEnabled("IW")) {
docState.infoStream.message("IW", "ERROR: " + msg);
}
// Document will be deleted above:
- throw new IllegalArgumentException(msg);
+ throw new IllegalArgumentException(msg, e);
} finally {
if (succeededInProcessingField == false && aborting) {
docState.docWriter.setAborting();
diff --git a/lucene/core/src/test/org/apache/lucene/index/TestExceedMaxTermLength.java b/lucene/core/src/test/org/apache/lucene/index/TestExceedMaxTermLength.java
index 8da74ae38b6..05773bfa3b8 100644
--- a/lucene/core/src/test/org/apache/lucene/index/TestExceedMaxTermLength.java
+++ b/lucene/core/src/test/org/apache/lucene/index/TestExceedMaxTermLength.java
@@ -97,6 +97,8 @@ public class TestExceedMaxTermLength extends LuceneTestCase {
msg.contains(maxLengthMsg));
assertTrue("IllegalArgumentException didn't mention field name ("+name+"): " + msg,
msg.contains(name));
+ assertTrue("IllegalArgumentException didn't mention original message: " + msg,
+ msg.contains("bytes can be at most") && msg.contains("in length; got"));
}
} finally {
w.shutdown();