From 5bc8c4da72cd902fd52414b8603c5f7a1ae07590 Mon Sep 17 00:00:00 2001 From: Daniel Widdis Date: Mon, 22 Jul 2024 10:47:23 -0700 Subject: [PATCH] Use instanceof instead of isAssignableFrom Signed-off-by: Daniel Widdis --- .../search/pipeline/common/SortResponseProcessor.java | 6 +++--- .../search/pipeline/common/SplitResponseProcessor.java | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/search-pipeline-common/src/main/java/org/opensearch/search/pipeline/common/SortResponseProcessor.java b/modules/search-pipeline-common/src/main/java/org/opensearch/search/pipeline/common/SortResponseProcessor.java index afbce83f4b1aa..e0bfd38b26376 100644 --- a/modules/search-pipeline-common/src/main/java/org/opensearch/search/pipeline/common/SortResponseProcessor.java +++ b/modules/search-pipeline-common/src/main/java/org/opensearch/search/pipeline/common/SortResponseProcessor.java @@ -174,10 +174,10 @@ private List getSortedValues(List values) { @SuppressWarnings("unchecked") private Comparable downcastToComparable(Object obj) { - if (obj == null) { - throw new IllegalArgumentException("field [" + sortField + "] contains a null value.]"); - } else if (Comparable.class.isAssignableFrom(obj.getClass())) { + if (obj instanceof Comparable) { return (Comparable) obj; + } else if (obj == null) { + throw new IllegalArgumentException("field [" + sortField + "] contains a null value.]"); } else { throw new IllegalArgumentException("field [" + sortField + "] of type [" + obj.getClass().getName() + "] is not comparable.]"); } diff --git a/modules/search-pipeline-common/src/main/java/org/opensearch/search/pipeline/common/SplitResponseProcessor.java b/modules/search-pipeline-common/src/main/java/org/opensearch/search/pipeline/common/SplitResponseProcessor.java index 0762f8f59b76e..bb3db4d9bc2c1 100644 --- a/modules/search-pipeline-common/src/main/java/org/opensearch/search/pipeline/common/SplitResponseProcessor.java +++ b/modules/search-pipeline-common/src/main/java/org/opensearch/search/pipeline/common/SplitResponseProcessor.java @@ -111,7 +111,7 @@ public SearchResponse processResponse(SearchRequest request, SearchResponse resp throw new IllegalArgumentException("field [" + splitField + "] is null, cannot split."); } Object val = docField.getValue(); - if (val == null || !String.class.isAssignableFrom(val.getClass())) { + if (!(val instanceof String)) { throw new IllegalArgumentException("field [" + splitField + "] is not a string, cannot split"); } Object[] strings = ((String) val).split(separator, preserveTrailing ? -1 : 0);