Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add null checks before binding#2406

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
filmor wants to merge1 commit intomasterfromnull-check-before-bind
Closed

Conversation

filmor
Copy link
Member

No description provided.

Comment on lines -291 to +297
internalstaticboolShouldBindMethod(MethodBasemb)
{
return(mb.IsPublic||mb.IsFamily||mb.IsFamilyOrAssembly);
}
internalstaticboolShouldBindMethod(MethodBasemb)=>
mb!=null&&
(mb.IsPublic||mb.IsFamily||mb.IsFamilyOrAssembly);

internalstaticboolShouldBindField(FieldInfofi)
{
return(fi.IsPublic||fi.IsFamily||fi.IsFamilyOrAssembly);
}
internalstaticboolShouldBindField(FieldInfofi)=>
fi!=null&&
(fi.IsPublic||fi.IsFamily||fi.IsFamilyOrAssembly);
Copy link
Member

Choose a reason for hiding this comment

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

Doesn't this just mask issues? I don't remember if we have nullability annotations on, but I think if you want to add a check here, it should throwArgumentNullException, and insteadnull should be handled at the call site.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

It does mask issues, but in a non-failing way which is a lot better than raising during startup (which effectively renders this library useless). This is an adaptation of what fixes#2405. Throwing an exception here is (apart from having a slightly better stacktrace) effectively the same as leaving the code unchanged.

Copy link
Member

Choose a reason for hiding this comment

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

I mean I suggest to check fornull at the call site which is what#2405 (comment) does, and optionally add an argument check inShouldBindMethod to throw something better thanNullReferenceException.

Simply returningfalse fornull inputs is error-prone.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

I don't agree, but I will also not put any more work into this. If you want to propose a different solution (in code), be my guest.

Copy link
Member

Choose a reason for hiding this comment

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

filmor reacted with thumbs up emoji
@filmor
Copy link
MemberAuthor

Superceded by#2409

@filmorfilmor closed thisJul 2, 2024
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@lostmsulostmsulostmsu left review comments

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

@filmor@lostmsu

[8]ページ先頭

©2009-2025 Movatter.jp