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

Validate arguments of public methods #2246

Conversation

Zombach
Copy link
Contributor

@Zombach Zombach commented Jul 24, 2024

Cause
An externally visible method dereferences one of its reference arguments without verifying whether that argument is null (Nothing in Visual Basic).

You can configure this rule to exclude certain types and parameters from analysis. You can also indicate null-check validation methods.

Rule description
All reference arguments that are passed to externally visible methods should be checked against null. If appropriate, throw an ArgumentNullException when the argument is null.

If a method can be called from an unknown assembly because it is declared public or protected, you should validate all parameters of the method. If the method is designed to be called only by known assemblies, mark the method internal and apply the InternalsVisibleToAttribute attribute to the assembly that contains the method.

Describe the solution you'd like
I suggest covering this with additional tests.
Check every reference argument in the public API ArgumentNullException.ThrowIfNull(source).

  • I started this PR by branching from the head of the default branch
  • I have targeted the PR to merge into the default branch
  • I have included unit tests for the issue/feature

Copy link

codecov bot commented Jul 24, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 85.33%. Comparing base (6d758f5) to head (bbc9a14).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2246      +/-   ##
==========================================
+ Coverage   84.08%   85.33%   +1.24%     
==========================================
  Files         313      313              
  Lines        7444     7444              
  Branches     1122     1122              
==========================================
+ Hits         6259     6352      +93     
+ Misses        814      746      -68     
+ Partials      371      346      -25     
Flag Coverage Δ
linux 85.33% <ø> (+1.24%) ⬆️
macos 85.33% <ø> (+1.24%) ⬆️
windows 85.33% <ø> (+1.24%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@martincostello martincostello merged commit 71f7057 into App-vNext:main Jul 25, 2024
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants