Apache Solr open-source search software
SOLR-13780: fix ClassCastException in NestableJsonFacet
Munendra S Nc22379253c2a
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex 756dd22f7d1..883732e117b 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -222,6 +222,8 @@ Bug Fixes* SOLR-13238: BlobHandler generates non-padded md5 (Jeff Walraven via janhoy)+* SOLR-13780: Fix ClassCastException in NestableJsonFacet (Tiago Martinho de Barros, Munendra S N)+Other Changes----------------------diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/response/json/NestableJsonFacet.java b/solr/solrj/src/java/org/apache/solr/client/solrj/response/json/NestableJsonFacet.javaindex b700c2cab86..52bc911de18 100644--- a/solr/solrj/src/java/org/apache/solr/client/solrj/response/json/NestableJsonFacet.java+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/response/json/NestableJsonFacet.java@@ -49,7 +49,7 @@ public class NestableJsonFacet {if (getKeysToSkip().contains(key)) {continue;} else if ("count".equals(key)) {- domainCount = (int) entry.getValue();+ domainCount = ((Number) entry.getValue()).longValue();} else if(entry.getValue() instanceof Number) { // Stat/agg facet valuestatFacetsByName.put(key, (Number)entry.getValue());} else if(entry.getValue() instanceof NamedList) { // Either heatmap/query/range/terms facetdiff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/response/NestableJsonFacetTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/response/NestableJsonFacetTest.javanew file mode 100644index 00000000000..3b40726d802--- /dev/null+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/response/NestableJsonFacetTest.java@@ -0,0 +1,85 @@+/*+ * 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.response;+++import java.util.Collections;++import org.apache.solr.SolrTestCaseJ4;+import org.apache.solr.client.solrj.response.json.NestableJsonFacet;+import org.apache.solr.common.util.NamedList;+import org.junit.Test;++public class NestableJsonFacetTest extends SolrTestCaseJ4 {++ @Test+ public void testParsing() {+ NamedList<Object> list = new NamedList<>();+ list.add("count", 12);+ NamedList<Object> buckets = new NamedList<Object>() {{+ add("val", "Nike");+ }};+ NamedList<Object> vals = new NamedList<Object>() {{+ add("numBuckets", 10);+ add("allBuckets", new NamedList<Object>(){{+ add("count", 12);+ }});+ add("before", new NamedList<Object>(){{+ add("count", 1);+ }});+ add("after", new NamedList<Object>(){{+ add("count", 2);+ }});+ add("between", new NamedList<Object>(){{+ add("count", 9);+ }});+ }};+ vals.add("buckets", Collections.singletonList(buckets));+ list.add("test", vals);+ NestableJsonFacet facet = new NestableJsonFacet(list);++ assertEquals(12L, facet.getCount());+ assertEquals(9L, facet.getBucketBasedFacets("test").getBetween());+ list.clear();++ list.add("count", 12L);+ buckets = new NamedList<Object>() {{+ add("val", "Nike");+ }};+ vals = new NamedList<Object>() {{+ add("numBuckets", 10L);+ add("allBuckets", new NamedList<Object>(){{+ add("count", 12L);+ }});+ add("before", new NamedList<Object>(){{+ add("count", 1L);+ }});+ add("after", new NamedList<Object>(){{+ add("count", 2L);+ }});+ add("between", new NamedList<Object>(){{+ add("count", 9L);+ }});+ }};+ vals.add("buckets", Collections.singletonList(buckets));+ list.add("test", vals);+ facet = new NestableJsonFacet(list);+ assertEquals(12L, facet.getCount());+ assertEquals(2L, facet.getBucketBasedFacets("test").getAfter());+ }+}