Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

SOLR-16363: DirectUpdateHandler2 should not throw UnknownFormatConversionException (#1121)

Kevin Risdenff494dd12b14
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 1f7b5af88e5..c5936a22744 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -74,6 +74,8 @@ Bug Fixes
* SOLR-16483: Fix IndexOutOfBounds in RecursiveNumericEvaluator (Bendegúz Ács via Kevin Risden)
+* SOLR-16363: DirectUpdateHandler2 should not throw UnknownFormatConversionException (Kevin Risden)
+
Build
---------------------
* Upgrade forbiddenapis to 3.4 (Uwe Schindler)
diff --git a/solr/core/src/java/org/apache/solr/update/DirectUpdateHandler2.java b/solr/core/src/java/org/apache/solr/update/DirectUpdateHandler2.java
index b9eeb90f526..dd15bfcad39 100644
--- a/solr/core/src/java/org/apache/solr/update/DirectUpdateHandler2.java
+++ b/solr/core/src/java/org/apache/solr/update/DirectUpdateHandler2.java
@@ -313,12 +313,12 @@ public class DirectUpdateHandler2 extends UpdateHandler
SolrException.ErrorCode.BAD_REQUEST,
String.format(
Locale.ROOT,
- "Exception writing document id %s to the index; possible analysis error: "
- + iae.getMessage()
- + (iae.getCause() instanceof BytesRefHash.MaxBytesLengthExceededException
- ? ". Perhaps the document has an indexed string field (solr.StrField) which is too large"
- : ""),
- cmd.getPrintableId()),
+ "Exception writing document id %s to the index; possible analysis error: %s%s",
+ cmd.getPrintableId(),
+ iae.getMessage(),
+ (iae.getCause() instanceof BytesRefHash.MaxBytesLengthExceededException
+ ? ". Perhaps the document has an indexed string field (solr.StrField) which is too large"
+ : "")),
iae);
} catch (RuntimeException t) {
throw new SolrException(
diff --git a/solr/core/src/test/org/apache/solr/update/TestUpdate.java b/solr/core/src/test/org/apache/solr/update/TestUpdate.java
index d64fda66ae7..a23e0bad45d 100644
--- a/solr/core/src/test/org/apache/solr/update/TestUpdate.java
+++ b/solr/core/src/test/org/apache/solr/update/TestUpdate.java
@@ -16,7 +16,6 @@
*/
package org.apache.solr.update;
-import java.io.IOException;
import java.util.concurrent.Callable;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.common.SolrException;
@@ -258,21 +257,44 @@ public class TestUpdate extends SolrTestCaseJ4 {
}
@Test // SOLR-8866
- public void testUpdateLogThrowsForUnknownTypes() throws IOException {
+ public void testUpdateLogThrowsForUnknownTypes() {
SolrInputDocument doc = new SolrInputDocument();
doc.addField("id", "444");
doc.addField("text", new Object()); // Object shouldn't be serialized later...
AddUpdateCommand cmd = new AddUpdateCommand(req());
cmd.solrDoc = doc;
- try {
- h.getCore().getUpdateHandler().addDoc(cmd); // should throw
- } catch (SolrException e) {
- if (e.getMessage().contains("serialize")) {
- return; // passed test
- }
- throw e;
- }
- fail();
+
+ SolrException thrown =
+ assertThrows(SolrException.class, () -> h.getCore().getUpdateHandler().addDoc(cmd));
+ assertEquals(
+ "TransactionLog doesn't know how to serialize class java.lang.Object; try implementing ObjectResolver?",
+ thrown.getMessage());
+ }
+
+ @Test // SOLR-16363
+ public void testAddDocLargeFieldThrowsSolrExceptionWrappedIllegalArgumentException() {
+ SolrInputDocument doc = new SolrInputDocument();
+ doc.addField("id", 555);
+ // use invalid String.format parameter in field name to test DirectUpdateHandler2#addDoc
+ // exception logging
+ doc.addField("t%)_s", "a".repeat(50000));
+
+ AddUpdateCommand cmd = new AddUpdateCommand(req());
+ cmd.solrDoc = doc;
+
+ SolrException thrown =
+ assertThrows(SolrException.class, () -> h.getCore().getUpdateHandler().addDoc(cmd));
+ assertEquals(IllegalArgumentException.class, thrown.getCause().getClass());
+ assertEquals(
+ "Exception writing document id 555 to the index; possible analysis error: "
+ + "Document contains at least one immense term in field=\"t%)_s\" "
+ + "(whose UTF8 encoding is longer than the max length 32766), all of which were skipped. "
+ + "Please correct the analyzer to not produce such terms. "
+ + "The prefix of the first immense term is: "
+ + "'[97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97]...', "
+ + "original message: bytes can be at most 32766 in length; got 50000. "
+ + "Perhaps the document has an indexed string field (solr.StrField) which is too large",
+ thrown.getMessage());
}
}