From 34aaea641dcd9c53f7527ccd51efa119060c0d2d Mon Sep 17 00:00:00 2001 From: Adrien Grand Date: Wed, 31 Aug 2016 15:30:26 +0200 Subject: [PATCH] Fix NPE when running a range query on a `scaled_float` with no upper bound. #20253 The null check was there, but on the wrong variable. --- .../elasticsearch/index/mapper/ScaledFloatFieldMapper.java | 2 +- .../elasticsearch/index/mapper/ScaledFloatFieldTypeTests.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/index/mapper/ScaledFloatFieldMapper.java b/core/src/main/java/org/elasticsearch/index/mapper/ScaledFloatFieldMapper.java index bcad6aa063e..3608da30f76 100644 --- a/core/src/main/java/org/elasticsearch/index/mapper/ScaledFloatFieldMapper.java +++ b/core/src/main/java/org/elasticsearch/index/mapper/ScaledFloatFieldMapper.java @@ -244,7 +244,7 @@ public class ScaledFloatFieldMapper extends FieldMapper { lo = Math.round(Math.ceil(dValue * scalingFactor)); } Long hi = null; - if (lowerTerm != null) { + if (upperTerm != null) { double dValue = NumberFieldMapper.NumberType.DOUBLE.parse(upperTerm).doubleValue(); if (includeUpper == false) { dValue = Math.nextDown(dValue); diff --git a/core/src/test/java/org/elasticsearch/index/mapper/ScaledFloatFieldTypeTests.java b/core/src/test/java/org/elasticsearch/index/mapper/ScaledFloatFieldTypeTests.java index b3cbaa291b4..59571b70231 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/ScaledFloatFieldTypeTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/ScaledFloatFieldTypeTests.java @@ -117,8 +117,8 @@ public class ScaledFloatFieldTypeTests extends FieldTypeTestCase { IndexSearcher searcher = newSearcher(reader); final int numQueries = 1000; for (int i = 0; i < numQueries; ++i) { - double l = (randomDouble() * 2 - 1) * 10000; - double u = (randomDouble() * 2 - 1) * 10000; + Double l = randomBoolean() ? null : (randomDouble() * 2 - 1) * 10000; + Double u = randomBoolean() ? null : (randomDouble() * 2 - 1) * 10000; boolean includeLower = randomBoolean(); boolean includeUpper = randomBoolean(); Query doubleQ = NumberFieldMapper.NumberType.DOUBLE.rangeQuery("double", l, u, includeLower, includeUpper);