Skip to content

Commit 8b9691f

Browse files
authored
throws std::invalid_argument if ParameterEvent is NULL. (#2814)
Signed-off-by: Tomoya Fujita <[email protected]>
1 parent 40e3fb7 commit 8b9691f

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

rclcpp/include/rclcpp/parameter_events_filter.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class ParameterEventsFilter
4545
* \param[in] names A list of parameter names of interest.
4646
* \param[in] types A list of the types of parameter events of iterest.
4747
* EventType NEW, DELETED, or CHANGED
48+
* \throws std::invalid_argument if event is NULL.
4849
*
4950
* Example Usage:
5051
*

rclcpp/src/rclcpp/parameter_events_filter.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ ParameterEventsFilter::ParameterEventsFilter(
2828
const std::vector<EventType> & types)
2929
: event_(event)
3030
{
31+
if (!event) {
32+
throw std::invalid_argument("event cannot be null");
33+
}
3134
if (std::find(types.begin(), types.end(), EventType::NEW) != types.end()) {
3235
for (auto & new_parameter : event->new_parameters) {
3336
if (std::find(names.begin(), names.end(), new_parameter.name) != names.end()) {

rclcpp/test/rclcpp/test_parameter_events_filter.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ class TestParameterEventFilter : public ::testing::Test
7272
/*
7373
Testing filters.
7474
*/
75+
TEST_F(TestParameterEventFilter, invalide_arguments) {
76+
EXPECT_THROW(
77+
rclcpp::ParameterEventsFilter(nullptr, {"new"}, {nt}),
78+
std::invalid_argument
79+
);
80+
}
81+
7582
TEST_F(TestParameterEventFilter, full_by_type) {
7683
auto res = rclcpp::ParameterEventsFilter(
7784
full,

0 commit comments

Comments
 (0)