This is an automated email from the ASF dual-hosted git repository.

krisden pushed a commit to branch branch_9x
in repository https://gitbox.apache.org/repos/asf/solr.git


The following commit(s) were added to refs/heads/branch_9x by this push:
     new 8731df16e99 SOLR-16483: Fix IndexOutOfBounds in 
RecursiveNumericEvaluator (#1054)
8731df16e99 is described below

commit 8731df16e99c5e381030f36f8fbb0ccb622a39f6
Author: Bendegúz Ács <[email protected]>
AuthorDate: Thu Oct 20 18:44:38 2022 +0200

    SOLR-16483: Fix IndexOutOfBounds in RecursiveNumericEvaluator (#1054)
---
 solr/CHANGES.txt                                   |  2 +
 .../solrj/io/eval/RecursiveNumericEvaluator.java   |  2 +-
 .../io/stream/eval/MovingAverageEvaluatorTest.java | 52 ++++++++++++++++++++++
 3 files changed, 55 insertions(+), 1 deletion(-)

diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index a902c22e6c1..d2cb1427986 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -44,6 +44,8 @@ Bug Fixes
 
 * SOLR-16160: UpdateXmlMessages duplicate data when data is removed and then 
added in the same message (Alex Deparvu via Kevin Risden)
 
+* SOLR-16483: Fix IndexOutOfBounds in RecursiveNumericEvaluator (Bendegúz Ács 
via Kevin Risden)
+
 Build
 ---------------------
 * Upgrade forbiddenapis to 3.4 (Uwe Schindler)
diff --git 
a/solr/solrj/src/java/org/apache/solr/client/solrj/io/eval/RecursiveNumericEvaluator.java
 
b/solr/solrj/src/java/org/apache/solr/client/solrj/io/eval/RecursiveNumericEvaluator.java
index 3aa4b85b42a..0670fc6cdac 100644
--- 
a/solr/solrj/src/java/org/apache/solr/client/solrj/io/eval/RecursiveNumericEvaluator.java
+++ 
b/solr/solrj/src/java/org/apache/solr/client/solrj/io/eval/RecursiveNumericEvaluator.java
@@ -51,7 +51,7 @@ public abstract class RecursiveNumericEvaluator extends 
RecursiveEvaluator {
     } else if (value instanceof Number) {
       return new BigDecimal(value.toString());
     } else if (value instanceof Collection) {
-      if (value instanceof List) {
+      if (value instanceof List && !((List) value).isEmpty()) {
         if (((List) value).get(0) instanceof Number) {
           return value;
         }
diff --git 
a/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/eval/MovingAverageEvaluatorTest.java
 
b/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/eval/MovingAverageEvaluatorTest.java
new file mode 100644
index 00000000000..9c7d45a0e9c
--- /dev/null
+++ 
b/solr/solrj/src/test/org/apache/solr/client/solrj/io/stream/eval/MovingAverageEvaluatorTest.java
@@ -0,0 +1,52 @@
+/*
+ * 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.
+ */
+package org.apache.solr.client.solrj.io.stream.eval;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.solr.SolrTestCase;
+import org.apache.solr.client.solrj.io.Tuple;
+import org.apache.solr.client.solrj.io.eval.MovingAverageEvaluator;
+import org.apache.solr.client.solrj.io.eval.StreamEvaluator;
+import org.apache.solr.client.solrj.io.stream.expr.StreamFactory;
+import org.junit.Test;
+
+public class MovingAverageEvaluatorTest extends SolrTestCase {
+
+  StreamFactory factory;
+  Map<String, Object> values;
+
+  public MovingAverageEvaluatorTest() {
+    super();
+
+    factory = new StreamFactory().withFunctionName("movingAvg", 
MovingAverageEvaluator.class);
+    values = new HashMap<>();
+  }
+
+  @Test
+  public void doesNotFailWithEmptyList() throws Exception {
+    StreamEvaluator evaluator = factory.constructEvaluator("movingAvg(a,30)");
+    Object result;
+
+    values.clear();
+    values.put("a", new ArrayList<Double>());
+    result = evaluator.evaluate(new Tuple(values));
+    assertEquals(Collections.emptyList(), result);
+  }
+}

Reply via email to