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

Fixed exception type for Guard.IsNotNullOr[Empty|WhiteSpace] #4327

Conversation

Sergio0694
Copy link
Member

@Sergio0694 Sergio0694 commented Oct 18, 2021

PR Type

What kind of change does this PR introduce?

  • Bugfix

What is the current behavior?

The Guard.IsNotNullOrEmpty and Guard.IsNotNullOrWhiteSpace APIs throw an ArgumentException even when the input is null. They should throw an ArgumentNullException in that case instead, for consistency.

What is the new behavior?

The right exception type is thrown. Same codegen for callers:

static void IsNotNullOrEmpty(string text, string name)
{
    if (!string.IsNullOrEmpty(text))
    {
        return;
    }

    ThrowArgumentExceptionForIsNotNullOrEmpty(text, name);
}
L0000: push ebp
L0001: mov ebp, esp
L0003: test ecx, ecx
L0005: je short L000f
L0007: cmp dword ptr [ecx+4], 0
L000b: jbe short L000f
L000d: pop ebp
L000e: ret
L000f: call dword ptr [0x290cc6fc]
L0015: int3

PR Checklist

Please check if your PR fulfills the following requirements:

  • Tested code with current supported SDKs
  • New component
    • Pull Request has been submitted to the documentation repository instructions. Link:
    • Added description of major feature to project description for NuGet package (4000 total character limit, so don't push entire description over that)
    • If control, added to Visual Studio Design project
  • Sample in sample app has been added / updated (for bug fixes / features)
  • New major technical changes in the toolkit have or will be added to the Wiki e.g. build changes, source generators, testing infrastructure, sample creation changes, etc...
  • Tests for the changes have been added (for bug fixes / features) (if applicable)
  • Header has been added to all new source files (run build/UpdateHeaders.bat)
  • Contains NO breaking changes

@Sergio0694 Sergio0694 added bug 🐛 An unexpected issue that highlights incorrect behavior .NET Components which are .NET based (non UWP specific) hotfix 🌶 labels Oct 18, 2021
@Sergio0694 Sergio0694 added this to the 7.1.1 milestone Oct 18, 2021
@michael-hawker michael-hawker merged commit 44ad0cc into CommunityToolkit:main Oct 18, 2021
@Sergio0694 Sergio0694 deleted the bugfix/incorrect-notnullorempty-exception branch October 18, 2021 17:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto merge ⚡ bug 🐛 An unexpected issue that highlights incorrect behavior hotfix 🌶 .NET Components which are .NET based (non UWP specific)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants