SOLR-13538: Fix classcastEx in TrieDateField for atomic updates (#764)

SOLR-13538: toNativeType () TrieDate & EnumField do not handle CharSequence properly
This commit is contained in:
S N Munendra 2019-07-05 10:13:12 +05:30 committed by Noble Paul
parent 36af839eb1
commit 5f1d342a96
3 changed files with 15 additions and 7 deletions

View File

@ -17,6 +17,10 @@
package org.apache.solr.schema;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
import java.io.IOException;
import java.lang.invoke.MethodHandles;
import java.util.Collections;
@ -24,11 +28,6 @@ import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
import org.apache.commons.lang3.math.NumberUtils;
import org.apache.lucene.index.IndexableField;
import org.apache.lucene.queries.function.ValueSource;
@ -314,7 +313,7 @@ public abstract class AbstractEnumField extends PrimitiveFieldType {
@Override
public Object toNativeType(Object val) {
if (val instanceof CharSequence || val instanceof String) {
if (val instanceof CharSequence) {
final String str = val.toString();
final Integer entry = enumMapping.enumStringToIntMap.get(str);
if (entry != null) {

View File

@ -97,7 +97,7 @@ public class TrieDateField extends TrieField implements DateValueFieldType {
@Override
public Object toNativeType(Object val) {
if (val instanceof CharSequence) {
return DateMathParser.parseMath(null, (String)val);
return DateMathParser.parseMath(null, val.toString());
}
return super.toNativeType(val);
}

View File

@ -23,6 +23,7 @@ import java.util.Date;
import org.apache.lucene.index.IndexableField;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.common.util.ByteArrayUtf8CharSequence;
import org.apache.solr.core.SolrConfig;
import org.apache.solr.core.SolrResourceLoader;
@ -61,4 +62,12 @@ public class DateFieldTest extends SolrTestCaseJ4 {
assertEquals(820454699990L, ((Date) f.toObject( out )).getTime() );
}
public void testToNativeType() {
FieldType ft = new TrieDateField();
ByteArrayUtf8CharSequence charSequence = new ByteArrayUtf8CharSequence("1995-12-31T23:59:59Z");
Date val = (Date) ft.toNativeType(charSequence);
assertEquals("1995-12-31T23:59:59Z", val.toInstant().toString());
}
}