Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

SOLR-2941: NullPointerException on clustering component initialization when schema does not have a unique key field

Stanisław Osiński011c81280498
diff --git a/solr/contrib/clustering/CHANGES.txt b/solr/contrib/clustering/CHANGES.txt
index 06307c1f508..369e6295b14 100644
--- a/solr/contrib/clustering/CHANGES.txt
+++ b/solr/contrib/clustering/CHANGES.txt
@@ -29,6 +29,9 @@ $Id$
* SOLR-2940: Passing values for custom Carrot2 fields. The custom field
mapping are defined using the carrot.custom parameter (Stanislaw Osinski).
+* SOLR-2941: NullPointerException on clustering component initialization
+ when schema does not have a unique key field (Stanislaw Osinski).
+
================== Release 3.5.0 ==================
(No Changes)
diff --git a/solr/contrib/clustering/src/java/org/apache/solr/handler/clustering/carrot2/CarrotClusteringEngine.java b/solr/contrib/clustering/src/java/org/apache/solr/handler/clustering/carrot2/CarrotClusteringEngine.java
index e2170f4d10f..d174ee14863 100644
--- a/solr/contrib/clustering/src/java/org/apache/solr/handler/clustering/carrot2/CarrotClusteringEngine.java
+++ b/solr/contrib/clustering/src/java/org/apache/solr/handler/clustering/carrot2/CarrotClusteringEngine.java
@@ -48,6 +48,7 @@ import org.apache.solr.handler.component.HighlightComponent;
import org.apache.solr.highlight.SolrHighlighter;
import org.apache.solr.request.LocalSolrQueryRequest;
import org.apache.solr.request.SolrQueryRequest;
+import org.apache.solr.schema.SchemaField;
import org.apache.solr.search.DocList;
import org.apache.solr.search.DocSlice;
import org.apache.solr.search.SolrIndexSearcher;
@@ -266,7 +267,13 @@ public class CarrotClusteringEngine extends SearchClusteringEngine {
new ClassLoaderLocator(core.getResourceLoader().getClassLoader())));
this.controller.init(initAttributes);
- this.idFieldName = core.getSchema().getUniqueKeyField().getName();
+
+ SchemaField uniqueField = core.getSchema().getUniqueKeyField();
+ if (uniqueField == null) {
+ throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,
+ CarrotClusteringEngine.class.getSimpleName() + " requires the schema to have a uniqueKeyField");
+ }
+ this.idFieldName = uniqueField.getName();
// Make sure the requested Carrot2 clustering algorithm class is available
String carrotAlgorithmClassName = initParams.get(CarrotParams.ALGORITHM);