From d67884a07c2946f10e505a80529af652c9162a08 Mon Sep 17 00:00:00 2001 From: Shalin Shekhar Mangar Date: Sat, 3 May 2014 13:01:36 +0000 Subject: [PATCH] SOLR-6023: FieldAnalysisRequestHandler throws NPE if no parameters are supplied git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1592195 13f79535-47bb-0310-9956-ffa450edef68 --- solr/CHANGES.txt | 3 +++ .../handler/FieldAnalysisRequestHandler.java | 2 +- .../FieldAnalysisRequestHandlerTest.java | 18 +++++++++++++++++- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index e8ecdcb9737..64a0b917ad1 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -132,6 +132,9 @@ Bug Fixes * SOLR-6037: Fixed incorrect max/sum/stddev for Date fields in StatsComponent (Brett Lucey, hossman) +* SOLR-6023: FieldAnalysisRequestHandler throws NPE if no parameters are supplied. + (shalin) + Other Changes --------------------- diff --git a/solr/core/src/java/org/apache/solr/handler/FieldAnalysisRequestHandler.java b/solr/core/src/java/org/apache/solr/handler/FieldAnalysisRequestHandler.java index 1e37fca4692..e1044da2e83 100644 --- a/solr/core/src/java/org/apache/solr/handler/FieldAnalysisRequestHandler.java +++ b/solr/core/src/java/org/apache/solr/handler/FieldAnalysisRequestHandler.java @@ -139,7 +139,7 @@ public class FieldAnalysisRequestHandler extends AnalysisRequestHandlerBase { } analysisRequest.setQuery(solrParams.get(AnalysisParams.QUERY, solrParams.get(CommonParams.Q))); - String value = solrParams.get(AnalysisParams.FIELD_VALUE); + String value = solrParams.required().get(AnalysisParams.FIELD_VALUE); Iterable streams = req.getContentStreams(); if (streams != null) { diff --git a/solr/core/src/test/org/apache/solr/handler/FieldAnalysisRequestHandlerTest.java b/solr/core/src/test/org/apache/solr/handler/FieldAnalysisRequestHandlerTest.java index ece55046f73..43cec6afe77 100644 --- a/solr/core/src/test/org/apache/solr/handler/FieldAnalysisRequestHandlerTest.java +++ b/solr/core/src/test/org/apache/solr/handler/FieldAnalysisRequestHandlerTest.java @@ -19,6 +19,7 @@ package org.apache.solr.handler; import org.apache.lucene.analysis.MockTokenizer; import org.apache.lucene.analysis.core.WhitespaceTokenizer; +import org.apache.solr.common.SolrException; import org.apache.solr.common.params.AnalysisParams; import org.apache.solr.common.params.CommonParams; import org.apache.solr.common.params.ModifiableSolrParams; @@ -379,5 +380,20 @@ public class FieldAnalysisRequestHandlerTest extends AnalysisRequestHandlerTestB assertToken(tokenList.get(4), new TokenInfo("a", null, "word", 12, 13, 4, new int[]{3,4,4}, null, false)); assertToken(tokenList.get(5), new TokenInfo("test", null, "word", 14, 18, 5, new int[]{4,5,5}, null, false)); } - + + public void testRequiredParamHandling() throws Exception { + ModifiableSolrParams params = new ModifiableSolrParams(); + params.add(CommonParams.Q, "fox brown"); + + SolrQueryRequest req = new LocalSolrQueryRequest(h.getCore(), params); + try { + FieldAnalysisRequest request = handler.resolveAnalysisRequest(req); + fail("A request with no parameters should not have succeeded"); + } catch (NullPointerException npe) { + fail("A request with no paramters should not result in NPE"); + } catch (SolrException e) { + assertEquals("A request with no parameters should have returned a BAD_REQUEST error", e.code(), + SolrException.ErrorCode.BAD_REQUEST.code); + } + } }