Skip to content

Commit 6152afe

Browse files
authored
Fix unchecked cast in dynamic action map getter (#15394)
Signed-off-by: Daniel Widdis <widdis@gmail.com>
1 parent 2301adf commit 6152afe

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6868
- Fix range aggregation optimization ignoring top level queries ([#15194](https://github.com/opensearch-project/OpenSearch/pull/15194))
6969
- Fix incorrect parameter names in MinHash token filter configuration handling ([#15233](https://github.com/opensearch-project/OpenSearch/pull/15233))
7070
- Fix split response processor not included in allowlist ([#15393](https://github.com/opensearch-project/OpenSearch/pull/15393))
71+
- Fix unchecked cast in dynamic action map getter ([#15394](https://github.com/opensearch-project/OpenSearch/pull/15394))
7172

7273
### Security
7374

server/src/main/java/org/opensearch/action/ActionModule.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -1200,9 +1200,12 @@ public void unregisterDynamicRoute(NamedRoute route) {
12001200
* @param route The {@link RestHandler.Route}.
12011201
* @return the corresponding {@link RestSendToExtensionAction} if it is registered, null otherwise.
12021202
*/
1203-
@SuppressWarnings("unchecked")
12041203
public RestSendToExtensionAction get(RestHandler.Route route) {
1205-
return routeRegistry.get(route);
1204+
if (route instanceof NamedRoute) {
1205+
return routeRegistry.get((NamedRoute) route);
1206+
}
1207+
// Only NamedRoutes are map keys so any other route is not in the map
1208+
return null;
12061209
}
12071210
}
12081211
}

server/src/test/java/org/opensearch/action/DynamicActionRegistryTests.java

+5
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.opensearch.extensions.action.ExtensionTransportAction;
2121
import org.opensearch.extensions.rest.RestSendToExtensionAction;
2222
import org.opensearch.rest.NamedRoute;
23+
import org.opensearch.rest.RestHandler;
2324
import org.opensearch.rest.RestRequest;
2425
import org.opensearch.tasks.Task;
2526
import org.opensearch.tasks.TaskManager;
@@ -85,13 +86,17 @@ public void testDynamicActionRegistryWithNamedRoutes() {
8586
RestSendToExtensionAction action2 = mock(RestSendToExtensionAction.class);
8687
NamedRoute r1 = new NamedRoute.Builder().method(RestRequest.Method.GET).path("/foo").uniqueName("foo").build();
8788
NamedRoute r2 = new NamedRoute.Builder().method(RestRequest.Method.PUT).path("/bar").uniqueName("bar").build();
89+
RestHandler.Route r3 = new RestHandler.Route(RestRequest.Method.DELETE, "/foo");
8890

8991
DynamicActionRegistry registry = new DynamicActionRegistry();
9092
registry.registerDynamicRoute(r1, action);
9193
registry.registerDynamicRoute(r2, action2);
9294

9395
assertTrue(registry.isActionRegistered("foo"));
96+
assertEquals(action, registry.get(r1));
9497
assertTrue(registry.isActionRegistered("bar"));
98+
assertEquals(action2, registry.get(r2));
99+
assertNull(registry.get(r3));
95100

96101
registry.unregisterDynamicRoute(r2);
97102

0 commit comments

Comments
 (0)