Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nullability: RuntimeHelpers.GetHashCode should accept null obj input #31819

Merged
merged 1 commit into from
Feb 6, 2020

Conversation

GrabYourPitchforks
Copy link
Member

Changes RuntimeHelpers.GetHashCode(object) to RuntimeHelpers.GetHashCode(object?). Both coreclr and mono already support passing null as an argument to this method.

int
mono_object_hash_internal (MonoObject* obj)
{
#ifdef HAVE_MOVING_COLLECTOR
LockWord lw;
unsigned int hash;
if (!obj)
return 0;

// Note that we obtain a sync block index without actually building a sync block.
// That's because a lot of objects are hashed, without requiring support for
FCIMPL1(INT32, ObjectNative::GetHashCode, Object* obj) {
CONTRACTL
{
FCALL_CHECK;
INJECT_FAULT(FCThrow(kOutOfMemoryException););
}
CONTRACTL_END;
VALIDATEOBJECT(obj);
if (obj == 0)
return 0;

And we already have a unit test for it.

int h5 = RuntimeHelpers.GetHashCode(null);
Assert.Equal(0, h5);

Copy link
Member

@stephentoub stephentoub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@stephentoub stephentoub merged commit 0d607a7 into dotnet:master Feb 6, 2020
@ghost ghost added the will_lock_this label Dec 6, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Jan 5, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants