Skip to content

Commit

Permalink
Naively cast unchecked exceptions
Browse files Browse the repository at this point in the history
Signed-off-by: Jay Deng <jayd0104@gmail.com>
  • Loading branch information
jed326 authored and Jay Deng committed Jun 30, 2023
1 parent a11f98b commit 1bc3857
Showing 1 changed file with 7 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
import org.opensearch.search.internal.SearchContext;
import org.opensearch.search.profile.query.ProfileCollectorManager;
import org.opensearch.search.query.QueryPhase.DefaultQueryPhaseSearcher;
import org.opensearch.tasks.TaskCancelledException;
import org.opensearch.transport.TransportException;

import java.io.IOException;
import java.util.LinkedList;
Expand Down Expand Up @@ -92,17 +90,12 @@ private static boolean searchWithCollectorManager(
if (re.getCause() instanceof ExecutionException || re.getCause() instanceof InterruptedException) {
Throwable t = re.getCause();
if (t.getCause() != null) {
if (t.getCause() instanceof TransportException) {
throw (TransportException) t.getCause();
}
if (t.getCause() instanceof TaskCancelledException) {
throw (TaskCancelledException) t.getCause();
}
rethrow(t.getCause());
}
}

// Rethrow any unexpected exception types
throw re;
rethrow(re.getCause());
}
if (searchContext.isSearchTimedOut()) {
assert timeoutSet : "TimeExceededException thrown even though timeout wasn't set";
Expand All @@ -122,4 +115,9 @@ private static boolean searchWithCollectorManager(
public AggregationProcessor aggregationProcessor(SearchContext searchContext) {
return aggregationProcessor;
}

@SuppressWarnings("unchecked")
private static <T extends Throwable> RuntimeException rethrow(Throwable throwable) throws T {
throw (T) throwable; // naively cast to unchecked exception
}
}

0 comments on commit 1bc3857

Please sign in to comment.