diff --git a/rclcpp/include/rclcpp/parameter_events_filter.hpp b/rclcpp/include/rclcpp/parameter_events_filter.hpp index 3aa70d8a85..98a2027276 100644 --- a/rclcpp/include/rclcpp/parameter_events_filter.hpp +++ b/rclcpp/include/rclcpp/parameter_events_filter.hpp @@ -45,6 +45,7 @@ class ParameterEventsFilter * \param[in] names A list of parameter names of interest. * \param[in] types A list of the types of parameter events of iterest. * EventType NEW, DELETED, or CHANGED + * \throws std::invalid_argument if event is NULL. * * Example Usage: * diff --git a/rclcpp/src/rclcpp/parameter_events_filter.cpp b/rclcpp/src/rclcpp/parameter_events_filter.cpp index be9882c85b..44e7f57d55 100644 --- a/rclcpp/src/rclcpp/parameter_events_filter.cpp +++ b/rclcpp/src/rclcpp/parameter_events_filter.cpp @@ -28,6 +28,9 @@ ParameterEventsFilter::ParameterEventsFilter( const std::vector & types) : event_(event) { + if (!event) { + throw std::invalid_argument("event cannot be null"); + } if (std::find(types.begin(), types.end(), EventType::NEW) != types.end()) { for (auto & new_parameter : event->new_parameters) { if (std::find(names.begin(), names.end(), new_parameter.name) != names.end()) { diff --git a/rclcpp/test/rclcpp/test_parameter_events_filter.cpp b/rclcpp/test/rclcpp/test_parameter_events_filter.cpp index a497a28c93..1c4d7c06c7 100644 --- a/rclcpp/test/rclcpp/test_parameter_events_filter.cpp +++ b/rclcpp/test/rclcpp/test_parameter_events_filter.cpp @@ -72,6 +72,13 @@ class TestParameterEventFilter : public ::testing::Test /* Testing filters. */ +TEST_F(TestParameterEventFilter, invalide_arguments) { + EXPECT_THROW( + rclcpp::ParameterEventsFilter(nullptr, {"new"}, {nt}), + std::invalid_argument + ); +} + TEST_F(TestParameterEventFilter, full_by_type) { auto res = rclcpp::ParameterEventsFilter( full,