Skip to content

Commit 1bc3857

Browse files
jed326Jay Deng
authored and
Jay Deng
committed
Naively cast unchecked exceptions
Signed-off-by: Jay Deng <jayd0104@gmail.com>
1 parent a11f98b commit 1bc3857

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

server/src/main/java/org/opensearch/search/query/ConcurrentQueryPhaseSearcher.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
import org.opensearch.search.internal.SearchContext;
2020
import org.opensearch.search.profile.query.ProfileCollectorManager;
2121
import org.opensearch.search.query.QueryPhase.DefaultQueryPhaseSearcher;
22-
import org.opensearch.tasks.TaskCancelledException;
23-
import org.opensearch.transport.TransportException;
2422

2523
import java.io.IOException;
2624
import java.util.LinkedList;
@@ -92,17 +90,12 @@ private static boolean searchWithCollectorManager(
9290
if (re.getCause() instanceof ExecutionException || re.getCause() instanceof InterruptedException) {
9391
Throwable t = re.getCause();
9492
if (t.getCause() != null) {
95-
if (t.getCause() instanceof TransportException) {
96-
throw (TransportException) t.getCause();
97-
}
98-
if (t.getCause() instanceof TaskCancelledException) {
99-
throw (TaskCancelledException) t.getCause();
100-
}
93+
rethrow(t.getCause());
10194
}
10295
}
10396

10497
// Rethrow any unexpected exception types
105-
throw re;
98+
rethrow(re.getCause());
10699
}
107100
if (searchContext.isSearchTimedOut()) {
108101
assert timeoutSet : "TimeExceededException thrown even though timeout wasn't set";
@@ -122,4 +115,9 @@ private static boolean searchWithCollectorManager(
122115
public AggregationProcessor aggregationProcessor(SearchContext searchContext) {
123116
return aggregationProcessor;
124117
}
118+
119+
@SuppressWarnings("unchecked")
120+
private static <T extends Throwable> RuntimeException rethrow(Throwable throwable) throws T {
121+
throw (T) throwable; // naively cast to unchecked exception
122+
}
125123
}

0 commit comments

Comments
 (0)