Skip to content

Commit 9084bce

Browse files
committed
ARROW-7734: [C++] check status details for nullptr in equality
1 parent bd08d0e commit 9084bce

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

cpp/src/arrow/status.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ class ARROW_EXPORT Status : public util::EqualityComparable<Status>,
292292
}
293293

294294
bool IsExecutionError() const { return code() == StatusCode::ExecutionError; }
295+
bool IsAlreadyExists() const { return code() == StatusCode::AlreadyExists; }
295296

296297
/// \brief Return a string representation of this status suitable for printing.
297298
///
@@ -385,8 +386,11 @@ bool Status::Equals(const Status& s) const {
385386
return false;
386387
}
387388

388-
if (detail() != s.detail() && !(*detail() == *s.detail())) {
389-
return false;
389+
if (detail() != s.detail()) {
390+
if ((detail() && !s.detail()) || (!detail() && s.detail())) {
391+
return false;
392+
}
393+
return *detail() == *s.detail();
390394
}
391395

392396
return code() == s.code() && message() == s.message();

cpp/src/arrow/status_test.cc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,17 @@ TEST(StatusTest, TestEquality) {
114114
ASSERT_NE(Status::Invalid("error"), Status::Invalid("other error"));
115115
}
116116

117+
TEST(StatusTest, TestDetailEquality) {
118+
const auto status_with_detail =
119+
arrow::Status(StatusCode::IOError, "", std::make_shared<TestStatusDetail>());
120+
const auto status_with_detail2 =
121+
arrow::Status(StatusCode::IOError, "", std::make_shared<TestStatusDetail>());
122+
const auto status_without_detail = arrow::Status::IOError("");
123+
124+
ASSERT_EQ(*status_with_detail.detail(), *status_with_detail2.detail());
125+
ASSERT_EQ(status_with_detail, status_with_detail2);
126+
ASSERT_NE(status_with_detail, status_without_detail);
127+
ASSERT_NE(status_without_detail, status_with_detail);
128+
}
129+
117130
} // namespace arrow

0 commit comments

Comments
 (0)