Skip to content

Commit

Permalink
ARROW-7734: [C++] check status details for nullptr in equality
Browse files Browse the repository at this point in the history
When checking statuses for equality, check to make sure that both have status detail objects before proceeding to compare those objects.

Closes apache#6332 from lidavidm/arrow-7734 and squashes the following commits:

9084bce <David Li> ARROW-7734:  check status details for nullptr in equality

Authored-by: David Li <li.davidm96@gmail.com>
Signed-off-by: Micah Kornfield <emkornfield@gmail.com>
  • Loading branch information
lidavidm authored and emkornfield committed Feb 3, 2020
1 parent 942a4d0 commit 49aada2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
8 changes: 6 additions & 2 deletions cpp/src/arrow/status.h
Expand Up @@ -292,6 +292,7 @@ class ARROW_EXPORT Status : public util::EqualityComparable<Status>,
}

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

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

if (detail() != s.detail() && !(*detail() == *s.detail())) {
return false;
if (detail() != s.detail()) {
if ((detail() && !s.detail()) || (!detail() && s.detail())) {
return false;
}
return *detail() == *s.detail();
}

return code() == s.code() && message() == s.message();
Expand Down
13 changes: 13 additions & 0 deletions cpp/src/arrow/status_test.cc
Expand Up @@ -114,4 +114,17 @@ TEST(StatusTest, TestEquality) {
ASSERT_NE(Status::Invalid("error"), Status::Invalid("other error"));
}

TEST(StatusTest, TestDetailEquality) {
const auto status_with_detail =
arrow::Status(StatusCode::IOError, "", std::make_shared<TestStatusDetail>());
const auto status_with_detail2 =
arrow::Status(StatusCode::IOError, "", std::make_shared<TestStatusDetail>());
const auto status_without_detail = arrow::Status::IOError("");

ASSERT_EQ(*status_with_detail.detail(), *status_with_detail2.detail());
ASSERT_EQ(status_with_detail, status_with_detail2);
ASSERT_NE(status_with_detail, status_without_detail);
ASSERT_NE(status_without_detail, status_with_detail);
}

} // namespace arrow

0 comments on commit 49aada2

Please sign in to comment.