Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unchecked cast in dynamic action map getter #15394

Merged
merged 2 commits into from
Aug 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Fixed array field name omission in flat_object function for nested JSON ([#13620](https://github.com/opensearch-project/OpenSearch/pull/13620))
- Fix range aggregation optimization ignoring top level queries ([#15194](https://github.com/opensearch-project/OpenSearch/pull/15194))
- Fix incorrect parameter names in MinHash token filter configuration handling ([#15233](https://github.com/opensearch-project/OpenSearch/pull/15233))
- Fix unchecked cast in dynamic action map getter ([#15394](https://github.com/opensearch-project/OpenSearch/pull/15394))

### Security

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1200,9 +1200,12 @@ public void unregisterDynamicRoute(NamedRoute route) {
* @param route The {@link RestHandler.Route}.
* @return the corresponding {@link RestSendToExtensionAction} if it is registered, null otherwise.
*/
@SuppressWarnings("unchecked")
public RestSendToExtensionAction get(RestHandler.Route route) {
return routeRegistry.get(route);
if (route instanceof NamedRoute) {
return routeRegistry.get((NamedRoute) route);
}
// Only NamedRoutes are map keys so any other route is not in the map
return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.opensearch.extensions.action.ExtensionTransportAction;
import org.opensearch.extensions.rest.RestSendToExtensionAction;
import org.opensearch.rest.NamedRoute;
import org.opensearch.rest.RestHandler;
import org.opensearch.rest.RestRequest;
import org.opensearch.tasks.Task;
import org.opensearch.tasks.TaskManager;
Expand Down Expand Up @@ -85,13 +86,17 @@ public void testDynamicActionRegistryWithNamedRoutes() {
RestSendToExtensionAction action2 = mock(RestSendToExtensionAction.class);
NamedRoute r1 = new NamedRoute.Builder().method(RestRequest.Method.GET).path("/foo").uniqueName("foo").build();
NamedRoute r2 = new NamedRoute.Builder().method(RestRequest.Method.PUT).path("/bar").uniqueName("bar").build();
RestHandler.Route r3 = new RestHandler.Route(RestRequest.Method.DELETE, "/foo");

DynamicActionRegistry registry = new DynamicActionRegistry();
registry.registerDynamicRoute(r1, action);
registry.registerDynamicRoute(r2, action2);

assertTrue(registry.isActionRegistered("foo"));
assertEquals(action, registry.get(r1));
assertTrue(registry.isActionRegistered("bar"));
assertEquals(action2, registry.get(r2));
assertNull(registry.get(r3));

registry.unregisterDynamicRoute(r2);

Expand Down
Loading