GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Add null checks before binding by filmor · Pull Request #2406 · pythonnet/pythonnet

Conversation

@filmor

@filmor filmor commented Jun 30, 2024

Copy link
Copy Markdown
Member

No description provided.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@filmor
Add null checks before binding
18afd6b
lostmsu
lostmsu reviewed Jul 1, 2024
View reviewed changes
Comment thread src/runtime/ClassManager.cs
Comment on lines -291 to +297
internal static bool ShouldBindMethod(MethodBase mb)
{
return (mb.IsPublic || mb.IsFamily || mb.IsFamilyOrAssembly);
}
internal static bool ShouldBindMethod(MethodBase mb) =>
mb != null &&
(mb.IsPublic || mb.IsFamily || mb.IsFamilyOrAssembly);

internal static bool ShouldBindField(FieldInfo fi)
{
return (fi.IsPublic || fi.IsFamily || fi.IsFamilyOrAssembly);
}
internal static bool ShouldBindField(FieldInfo fi) =>
fi != null &&
(fi.IsPublic || fi.IsFamily || fi.IsFamilyOrAssembly);

@lostmsu lostmsu Jul 1, 2024

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

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 throw ArgumentNullException, and instead null should be handled at the call site.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@filmor filmor Jul 1, 2024

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@lostmsu lostmsu Jul 1, 2024

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

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 for null at the call site which is what #2405 (comment) does, and optionally add an argument check in ShouldBindMethod to throw something better than NullReferenceException.

Simply returning false for null inputs is error-prone.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@filmor filmor Jul 1, 2024

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@lostmsu lostmsu Jul 1, 2024

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

@filmor opened #2409

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

filmor reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@filmor

filmor commented Jul 2, 2024

Copy link
Copy Markdown
Member Author

Superceded by #2409

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@filmor filmor closed this Jul 2, 2024
@filmor
filmor deleted the null-check-before-bind branch October 21, 2025 09:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@lostmsu lostmsu lostmsu left review comments

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@filmor @lostmsu
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.