diff --git a/core/src/main/java/org/elasticsearch/common/CheckedFunction.java b/core/src/main/java/org/elasticsearch/common/CheckedFunction.java new file mode 100644 index 00000000000..4a2d222db0b --- /dev/null +++ b/core/src/main/java/org/elasticsearch/common/CheckedFunction.java @@ -0,0 +1,30 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch 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.elasticsearch.common; + +import java.util.function.Function; + +/** + * A {@link Function}-like interface which allows throwing checked exceptions. + */ +@FunctionalInterface +public interface CheckedFunction { + R apply(T t) throws E; +} diff --git a/core/src/main/java/org/elasticsearch/index/query/QueryShardContext.java b/core/src/main/java/org/elasticsearch/index/query/QueryShardContext.java index e075368a2b4..93881306f08 100644 --- a/core/src/main/java/org/elasticsearch/index/query/QueryShardContext.java +++ b/core/src/main/java/org/elasticsearch/index/query/QueryShardContext.java @@ -29,6 +29,7 @@ import org.apache.lucene.search.similarities.Similarity; import org.apache.lucene.util.SetOnce; import org.elasticsearch.Version; import org.elasticsearch.client.Client; +import org.elasticsearch.common.CheckedFunction; import org.elasticsearch.common.ParsingException; import org.elasticsearch.common.Strings; import org.elasticsearch.common.bytes.BytesReference; @@ -308,12 +309,7 @@ public class QueryShardContext extends QueryRewriteContext { }); } - @FunctionalInterface - private interface CheckedFunction { - R apply(T t) throws IOException; - } - - private ParsedQuery toQuery(QueryBuilder queryBuilder, CheckedFunction filterOrQuery) { + private ParsedQuery toQuery(QueryBuilder queryBuilder, CheckedFunction filterOrQuery) { reset(); try { QueryBuilder rewriteQuery = QueryBuilder.rewriteQuery(queryBuilder, this);