SOLR-13285: Updates with enum fields and javabin cause ClassCastException

This commit is contained in:
Noble Paul 2019-03-05 06:11:50 +11:00
parent 876fcb7f7b
commit 7771d7bb84
3 changed files with 27 additions and 1 deletions

View File

@ -92,6 +92,8 @@ Bug Fixes
* SOLR-9882: 500 error code on breaching timeAllowed by core and distributed (fsv) search,
old and json facets (Mikhail Khludnev)
* SOLR-13285: Updates with enum fields and javabin cause ClassCastException (noble)
Improvements
----------------------
* SOLR-12999: Index replication could delete segments before downloading segments from master if there is not enough

View File

@ -53,6 +53,8 @@ import org.noggit.CharArr;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static org.apache.solr.common.util.ByteArrayUtf8CharSequence.convertCharSeq;
/**
* Defines a space-efficient serialization/deserialization format for transferring data.
* <p>
@ -818,7 +820,7 @@ public class JavaBinCodec implements PushWriter {
*/
public EnumFieldValue readEnumFieldValue(DataInputInputStream dis) throws IOException {
Integer intValue = (Integer) readVal(dis);
String stringValue = (String) readVal(dis);
String stringValue = (String) convertCharSeq (readVal(dis));
return new EnumFieldValue(intValue, stringValue);
}

View File

@ -65,6 +65,20 @@ public class TestJavaBinCodec extends SolrTestCaseJ4 {
}
}
public void testReadAsCharSeq() throws Exception {
List<Object> types = new ArrayList<>();
SolrInputDocument idoc = new SolrInputDocument();
idoc.addField("foo", "bar");
idoc.addField("foos", Arrays.asList("bar1","bar2"));
idoc.addField("enumf", new EnumFieldValue(1, "foo"));
types.add(idoc);
compareObjects(
(List) getObject(getBytes(types, true)),
(List) types
);
}
public static SolrDocument generateSolrDocumentWithChildDocs() {
SolrDocument parentDocument = new SolrDocument();
parentDocument.addField("id", "1");
@ -284,6 +298,14 @@ public class TestJavaBinCodec extends SolrTestCaseJ4 {
}
}
private static byte[] getBytes(Object o, boolean readAsCharSeq) throws IOException {
try (JavaBinCodec javabin = new JavaBinCodec(); ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
javabin.readStringAsCharSeq = readAsCharSeq;
javabin.marshal(o, baos);
return baos.toByteArray();
}
}
private static Object getObject(byte[] bytes) throws IOException {
try (JavaBinCodec jbc = new JavaBinCodec()) {
return jbc.unmarshal(new ByteArrayInputStream(bytes));