lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From romseyg...@apache.org
Subject svn commit: r1715749 - in /lucene/dev/trunk/solr: CHANGES.txt solrj/src/java/org/apache/solr/client/solrj/request/UpdateRequest.java solrj/src/test/org/apache/solr/client/solrj/request/TestUpdateRequest.java
Date Mon, 23 Nov 2015 09:50:04 GMT
Author: romseygeek
Date: Mon Nov 23 09:50:03 2015
New Revision: 1715749

URL: http://svn.apache.org/viewvc?rev=1715749&view=rev
Log:
SOLR-8194: Improve error reporting of nulls in UpdateRequest

Added:
    lucene/dev/trunk/solr/solrj/src/test/org/apache/solr/client/solrj/request/TestUpdateRequest.java
  (with props)
Modified:
    lucene/dev/trunk/solr/CHANGES.txt
    lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/client/solrj/request/UpdateRequest.java

Modified: lucene/dev/trunk/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/CHANGES.txt?rev=1715749&r1=1715748&r2=1715749&view=diff
==============================================================================
--- lucene/dev/trunk/solr/CHANGES.txt (original)
+++ lucene/dev/trunk/solr/CHANGES.txt Mon Nov 23 09:50:03 2015
@@ -554,6 +554,9 @@ Other Changes
 * SOLR-8303: CustomBufferedIndexInput now includes resource description when
   throwing EOFException.  (Mike Drob via Uwe Schindler)
 
+* SOLR-8194: Improve error reporting for null documents in UpdateRequest (Markus
+  Jelsma, Alan Woodward)
+
 ==================  5.3.1 ==================
 
 Bug Fixes

Modified: lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/client/solrj/request/UpdateRequest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/client/solrj/request/UpdateRequest.java?rev=1715749&r1=1715748&r2=1715749&view=diff
==============================================================================
--- lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/client/solrj/request/UpdateRequest.java
(original)
+++ lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/client/solrj/request/UpdateRequest.java
Mon Nov 23 09:50:03 2015
@@ -17,16 +17,6 @@
 
 package org.apache.solr.client.solrj.request;
 
-import org.apache.solr.client.solrj.impl.LBHttpSolrClient;
-import org.apache.solr.client.solrj.util.ClientUtils;
-import org.apache.solr.common.SolrInputDocument;
-import org.apache.solr.common.cloud.DocCollection;
-import org.apache.solr.common.cloud.DocRouter;
-import org.apache.solr.common.cloud.Slice;
-import org.apache.solr.common.params.ModifiableSolrParams;
-import org.apache.solr.common.util.ContentStream;
-import org.apache.solr.common.util.XML;
-
 import java.io.IOException;
 import java.io.StringWriter;
 import java.io.Writer;
@@ -38,8 +28,19 @@ import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
+import java.util.Objects;
 import java.util.Set;
 
+import org.apache.solr.client.solrj.impl.LBHttpSolrClient;
+import org.apache.solr.client.solrj.util.ClientUtils;
+import org.apache.solr.common.SolrInputDocument;
+import org.apache.solr.common.cloud.DocCollection;
+import org.apache.solr.common.cloud.DocRouter;
+import org.apache.solr.common.cloud.Slice;
+import org.apache.solr.common.params.ModifiableSolrParams;
+import org.apache.solr.common.util.ContentStream;
+import org.apache.solr.common.util.XML;
+
 /**
  * 
  * 
@@ -88,25 +89,50 @@ public class UpdateRequest extends Abstr
   
   // ---------------------------------------------------------------------------
   // ---------------------------------------------------------------------------
-  
+
+  /**
+   * Add a SolrInputDocument to this request
+   *
+   * @throws NullPointerException if the document is null
+   */
   public UpdateRequest add(final SolrInputDocument doc) {
+    Objects.requireNonNull(doc, "Cannot add a null SolrInputDocument");
     if (documents == null) {
       documents = new LinkedHashMap<>();
     }
     documents.put(doc, null);
     return this;
   }
-  
+
+  /**
+   * Add a SolrInputDocument to this request
+   * @param doc the document
+   * @param overwrite true if the document should overwrite existing docs with the same id
+   * @throws NullPointerException if the document is null
+   */
   public UpdateRequest add(final SolrInputDocument doc, Boolean overwrite) {
     return add(doc, null, overwrite);
   }
-  
+
+  /**
+   * Add a SolrInputDocument to this request
+   * @param doc the document
+   * @param commitWithin the time horizon by which the document should be committed (in ms)
+   * @throws NullPointerException if the document is null
+   */
   public UpdateRequest add(final SolrInputDocument doc, Integer commitWithin) {
     return add(doc, commitWithin, null);
   }
-  
-  public UpdateRequest add(final SolrInputDocument doc, Integer commitWithin,
-      Boolean overwrite) {
+
+  /**
+   * Add a SolrInputDocument to this request
+   * @param doc the document
+   * @param commitWithin the time horizon by which the document should be committed (in ms)
+   * @param overwrite true if the document should overwrite existing docs with the same id
+   * @throws NullPointerException if the document is null
+   */
+  public UpdateRequest add(final SolrInputDocument doc, Integer commitWithin, Boolean overwrite)
{
+    Objects.requireNonNull(doc, "Cannot add a null SolrInputDocument");
     if (documents == null) {
       documents = new LinkedHashMap<>();
     }
@@ -118,12 +144,18 @@ public class UpdateRequest extends Abstr
     
     return this;
   }
-  
+
+  /**
+   * Add a collection of SolrInputDocuments to this request
+   *
+   * @throws NullPointerException if any of the documents in the collection are null
+   */
   public UpdateRequest add(final Collection<SolrInputDocument> docs) {
     if (documents == null) {
       documents = new LinkedHashMap<>();
     }
     for (SolrInputDocument doc : docs) {
+      Objects.requireNonNull(doc, "Cannot add a null SolrInputDocument");
       documents.put(doc, null);
     }
     return this;

Added: lucene/dev/trunk/solr/solrj/src/test/org/apache/solr/client/solrj/request/TestUpdateRequest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/solrj/src/test/org/apache/solr/client/solrj/request/TestUpdateRequest.java?rev=1715749&view=auto
==============================================================================
--- lucene/dev/trunk/solr/solrj/src/test/org/apache/solr/client/solrj/request/TestUpdateRequest.java
(added)
+++ lucene/dev/trunk/solr/solrj/src/test/org/apache/solr/client/solrj/request/TestUpdateRequest.java
Mon Nov 23 09:50:03 2015
@@ -0,0 +1,69 @@
+package org.apache.solr.client.solrj.request;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.util.Arrays;
+
+import org.apache.solr.common.SolrInputDocument;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+public class TestUpdateRequest {
+
+  @Rule
+  public ExpectedException exception = ExpectedException.none();
+
+  @Before
+  public void expectException() {
+    exception.expect(NullPointerException.class);
+    exception.expectMessage("Cannot add a null SolrInputDocument");
+  }
+
+  @Test
+  public void testCannotAddNullSolrInputDocument() {
+    UpdateRequest req = new UpdateRequest();
+    req.add((SolrInputDocument) null);
+  }
+
+  @Test
+  public void testCannotAddNullDocumentWithOverwrite() {
+    UpdateRequest req = new UpdateRequest();
+    req.add(null, true);
+  }
+
+  @Test
+  public void testCannotAddNullDocumentWithCommitWithin() {
+    UpdateRequest req = new UpdateRequest();
+    req.add(null, 1);
+  }
+
+  @Test
+  public void testCannotAddNullDocumentWithParameters() {
+    UpdateRequest req = new UpdateRequest();
+    req.add(null, 1, true);
+  }
+
+  @Test
+  public void testCannotAddNullDocumentAsPartOfList() {
+    UpdateRequest req = new UpdateRequest();
+    req.add(Arrays.asList(new SolrInputDocument(), new SolrInputDocument(), null));
+  }
+
+}



Mime
View raw message