From 49aada21d6f4a0e0e0a8cc651884fe402eaeb5fd Mon Sep 17 00:00:00 2001
From: David Li
Date: Sun, 2 Feb 2020 19:42:55 -0800
Subject: [PATCH] ARROW-7734: [C++] check status details for nullptr in
equality
When checking statuses for equality, check to make sure that both have status detail objects before proceeding to compare those objects.
Closes #6332 from lidavidm/arrow-7734 and squashes the following commits:
9084bcec7 ARROW-7734: check status details for nullptr in equality
Authored-by: David Li
Signed-off-by: Micah Kornfield
---
cpp/src/arrow/status.h | 8 ++++++--
cpp/src/arrow/status_test.cc | 13 +++++++++++++
2 files changed, 19 insertions(+), 2 deletions(-)
diff --git a/cpp/src/arrow/status.h b/cpp/src/arrow/status.h
index c44e311b7b281..df3ea6b9af657 100644
--- a/cpp/src/arrow/status.h
+++ b/cpp/src/arrow/status.h
@@ -292,6 +292,7 @@ class ARROW_EXPORT Status : public util::EqualityComparable,
}
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.
///
@@ -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();
diff --git a/cpp/src/arrow/status_test.cc b/cpp/src/arrow/status_test.cc
index 593ad2194bfb1..fc5a7ec45cf38 100644
--- a/cpp/src/arrow/status_test.cc
+++ b/cpp/src/arrow/status_test.cc
@@ -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());
+ const auto status_with_detail2 =
+ arrow::Status(StatusCode::IOError, "", std::make_shared());
+ 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