From c5ce78ed44ec3b96574b22c9bd4bb0ea50631779 Mon Sep 17 00:00:00 2001 From: Colin Goodheart-Smithe Date: Wed, 6 Apr 2016 08:37:27 +0100 Subject: [PATCH] Aggregations: Fixes NPE when no window is specified in moving average request This PR fixes a bug where a NPE was thrown when parsing a moving average pipeline aggregation request which did not specify a window size. Closes #17516 --- .../pipeline/movavg/MovAvgParser.java | 2 +- .../BasePipelineAggregationTestCase.java | 6 ++-- .../pipeline/moving/avg/MovAvgTests.java | 35 +++++++++++++++++++ 3 files changed, 39 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/movavg/MovAvgParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/movavg/MovAvgParser.java index 96a7dacb0f3..bbc2130f09a 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/movavg/MovAvgParser.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/movavg/MovAvgParser.java @@ -163,7 +163,7 @@ public class MovAvgParser implements PipelineAggregator.Parser { MovAvgModel movAvgModel; try { - movAvgModel = modelParser.parse(settings, pipelineAggregatorName, window, context.parseFieldMatcher()); + movAvgModel = modelParser.parse(settings, pipelineAggregatorName, factory.window(), context.parseFieldMatcher()); } catch (ParseException exception) { throw new ParsingException(parser.getTokenLocation(), "Could not parse settings for model [" + model + "].", exception); } diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/BasePipelineAggregationTestCase.java b/core/src/test/java/org/elasticsearch/search/aggregations/BasePipelineAggregationTestCase.java index 16bba36ed77..d63d61ab4ed 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/BasePipelineAggregationTestCase.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/BasePipelineAggregationTestCase.java @@ -102,9 +102,9 @@ public abstract class BasePipelineAggregationTestCase newAgg = aggParsers.pipelineAggregator(expected.getWriteableName()).parse(expected.name(), parser, + parseContext); + assertSame(XContentParser.Token.END_OBJECT, parser.currentToken()); + assertSame(XContentParser.Token.END_OBJECT, parser.nextToken()); + assertSame(XContentParser.Token.END_OBJECT, parser.nextToken()); + assertNull(parser.nextToken()); + assertNotNull(newAgg); + assertNotSame(newAgg, expected); + assertEquals(expected, newAgg); + assertEquals(expected.hashCode(), newAgg.hashCode()); + } }