JavaBinUpdateRequestCodec (and javabin codec) fails when the field type of a
multivalued field is a Set (or any type that is identified as an instance of
iterable)
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
Key: SOLR-1870
URL: https://issues.apache.org/jira/browse/SOLR-1870
Project: Solr
Issue Type: Bug
Components: update
Affects Versions: 1.4
Reporter: Prasanna Ranganathan
Priority: Minor
When the field type of a field in a SolrInputDocument is a Collection based on
the Set interface, the JavaBinUpdate request fails. It works when sending the
document data over XML.
I encountered this error when updating my indexer to write documents in the
binary format. I initially got a ClassCastException and after digging into it
found the likely cause for it.
The following piece of code added to 'public void simple() throws IOException'
method in TestUpdateRequestCodec.java illustrates the error.
doc = new SolrInputDocument();
Collection<String> foobar = new HashSet<String>();
foobar.add("baz1");
foobar.add("baz2");
doc.addField("foobar",foobar);
updateRequest.add(doc);
The test fails for any Collection derived from the Set interface but will work
if the Collection is a List / Array or other types. The stack trace is as
follows:
java.lang.ClassCastException: java.lang.String
at
org.apache.solr.client.solrj.request.JavaBinUpdateRequestCodec$2.readIterator(JavaBinUpdateRequestCodec.java:121)
at
org.apache.solr.common.util.JavaBinCodec.readVal(JavaBinCodec.java:210)
at
org.apache.solr.client.solrj.request.JavaBinUpdateRequestCodec$2.readNamedList(JavaBinUpdateRequestCodec.java:107)
at
org.apache.solr.common.util.JavaBinCodec.readVal(JavaBinCodec.java:175)
at
org.apache.solr.common.util.JavaBinCodec.readArray(JavaBinCodec.java:405)
at
org.apache.solr.common.util.JavaBinCodec.readVal(JavaBinCodec.java:171)
at
org.apache.solr.client.solrj.request.JavaBinUpdateRequestCodec$2.readIterator(JavaBinUpdateRequestCodec.java:119)
at
org.apache.solr.common.util.JavaBinCodec.readVal(JavaBinCodec.java:210)
at
org.apache.solr.client.solrj.request.JavaBinUpdateRequestCodec$2.readNamedList(JavaBinUpdateRequestCodec.java:107)
at
org.apache.solr.common.util.JavaBinCodec.readVal(JavaBinCodec.java:175)
at
org.apache.solr.common.util.JavaBinCodec.unmarshal(JavaBinCodec.java:101)
at
org.apache.solr.client.solrj.request.JavaBinUpdateRequestCodec.unmarshal(JavaBinUpdateRequestCodec.java:126)
at
org.apache.solr.client.solrj.request.TestUpdateRequestCodec.simple(TestUpdateRequestCodec.java:82)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at
org.junit.internal.runners.TestMethodRunner.executeMethodBody(TestMethodRunner.java:99)
at
org.junit.internal.runners.TestMethodRunner.runUnprotected(TestMethodRunner.java:81)
at
org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
at
org.junit.internal.runners.TestMethodRunner.runMethod(TestMethodRunner.java:75)
at
org.junit.internal.runners.TestMethodRunner.run(TestMethodRunner.java:45)
at
org.junit.internal.runners.TestClassMethodsRunner.invokeTestMethod(TestClassMethodsRunner.java:66)
at
org.junit.internal.runners.TestClassMethodsRunner.run(TestClassMethodsRunner.java:35)
at
org.junit.internal.runners.TestClassRunner$1.runUnprotected(TestClassRunner.java:42)
at
org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
at
org.junit.internal.runners.TestClassRunner.run(TestClassRunner.java:52)
at com.intellij.rt.junit4.Junit4ClassSuite.run(Junit4ClassSuite.java:99)
at
com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:40)
The error most likely is in the way javabin codec encodes Sets. In the public
boolean writeKnownType(Object val) method in JavaBinCodec.java, a Set is
recognized as an instance of iterable and the writeIterator method is called.
I briefly looked at the writeIterator and readIterator methods and was unable
to pinpoint the error. I also looked at the javabin encoded byte stream (not
exactly a good way to debug..) and it did not look like it was right.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.