diff --git a/src/ray/common/id.cc b/src/ray/common/id.cc index eae791b7d..bdf3f57c4 100644 --- a/src/ray/common/id.cc +++ b/src/ray/common/id.cc @@ -372,7 +372,7 @@ ObjectID ObjectID::GenerateObjectId(const std::string &task_id_binary, ObjectIDFlagsType flags, ObjectIDIndexType object_index) { RAY_CHECK(task_id_binary.size() == TaskID::Size()); - ObjectID ret = ObjectID::Nil(); + ObjectID ret; std::memcpy(ret.id_, task_id_binary.c_str(), TaskID::kLength); std::memcpy(ret.id_ + TaskID::kLength, &flags, sizeof(flags)); std::memcpy(ret.id_ + TaskID::kLength + kFlagsBytesLength, &object_index, diff --git a/src/ray/common/id.h b/src/ray/common/id.h index 8555b2000..3eacdf256 100644 --- a/src/ray/common/id.h +++ b/src/ray/common/id.h @@ -455,7 +455,7 @@ template T BaseID::FromBinary(const std::string &binary) { RAY_CHECK(binary.size() == T::Size() || binary.size() == 0) << "expected size is " << T::Size() << ", but got " << binary.size(); - T t = T::Nil(); + T t; std::memcpy(t.MutableData(), binary.data(), binary.size()); return t; } diff --git a/src/ray/common/id_test.cc b/src/ray/common/id_test.cc index 7dae9b8c8..960ea149e 100644 --- a/src/ray/common/id_test.cc +++ b/src/ray/common/id_test.cc @@ -113,6 +113,16 @@ TEST(NilTest, TestIsNil) { ASSERT_TRUE(ObjectID::Nil().IsNil()); } +TEST(HashTest, TestNilHash) { + // Manually trigger the hash calculation of the static global nil ID. + auto nil_hash = ObjectID::Nil().Hash(); + ObjectID id1 = ObjectID::FromRandom(); + ASSERT_NE(nil_hash, id1.Hash()); + ObjectID id2 = ObjectID::FromBinary(ObjectID::FromRandom().Binary()); + ASSERT_NE(nil_hash, id2.Hash()); + ASSERT_NE(id1.Hash(), id2.Hash()); +} + } // namespace ray int main(int argc, char **argv) {