Apache Solr open-source search software
check for null copyField source, delay some allocations
Yonik Seeley951dab2048c3
diff --git a/src/java/org/apache/solr/update/DocumentBuilder.java b/src/java/org/apache/solr/update/DocumentBuilder.javaindex 4b861acdce1..42c884ce653 100644--- a/src/java/org/apache/solr/update/DocumentBuilder.java+++ b/src/java/org/apache/solr/update/DocumentBuilder.java@@ -43,7 +43,7 @@ import org.apache.solr.schema.SchemaField;public class DocumentBuilder {private final IndexSchema schema;private Document doc;- private HashMap<String,String> map = new HashMap<String,String>();+ private HashMap<String,String> map;public DocumentBuilder(IndexSchema schema) {this.schema = schema;@@ -51,7 +51,7 @@ public class DocumentBuilder {public void startDoc() {doc = new Document();- map.clear();+ map = new HashMap<String,String>();}protected void addSingleField(SchemaField sfield, String val, float boost) {@@ -69,11 +69,6 @@ public class DocumentBuilder {+ ": first='" + oldValue + "' second='" + val + "'");}}-- if( doc == null ) {- throw new SolrException( SolrException.ErrorCode.SERVER_ERROR,- "must call startDoc() before adding fields!" );- }// field.setBoost(boost);doc.add(field);@@ -122,18 +117,21 @@ public class DocumentBuilder {// Check for all required fields -- Note, all fields with a// default value are defacto 'required' fields.- List<String> missingFields = new ArrayList<String>( schema.getRequiredFields().size() );+ List<String> missingFields = null;for (SchemaField field : schema.getRequiredFields()) {if (doc.getField(field.getName() ) == null) {if (field.getDefaultValue() != null) {doc.add( field.createField( field.getDefaultValue(), 1.0f ) );} else {+ if (missingFields==null) {+ missingFields = new ArrayList<String>(1);+ }missingFields.add(field.getName());}}}- if (missingFields.size() > 0) {+ if (missingFields != null) {StringBuilder builder = new StringBuilder();// add the uniqueKey if possibleif( schema.getUniqueKeyField() != null ) {@@ -181,7 +179,7 @@ public class DocumentBuilder {// Make sure it has the correct numberCollection<Object> vals = doc.getFieldValues( name );- if( vals.size() > 1 && !sfield.multiValued() ) {+ if(vals.size() > 1 && sfield!=null && !sfield.multiValued() ) {throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,"ERROR: multiple values encountered for non multiValued field " +sfield.getName() + ": " +vals.toString() );