Skip to content

Remove always-true condition #3009

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

Merged
merged 1 commit into from
Jan 7, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public override object ConvertTo(ITypeDescriptorContext context, CultureInfo cul
}

String strKey = MatchKey(key, culture);
if (strKey != null && (strKey.Length != 0 || strKey == String.Empty))
if (strKey != null)
{
return strKey;
}
Expand All @@ -142,7 +142,7 @@ public override object ConvertTo(ITypeDescriptorContext context, CultureInfo cul

private object GetKey(string keyToken, CultureInfo culture)
{
if (keyToken == String.Empty)
if (keyToken.Length == 0)
Copy link
Member

Choose a reason for hiding this comment

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

NullReferenceException?

Could you use string.IsNullOrEmpty ?

Copy link
Member Author

Choose a reason for hiding this comment

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

The caller code is:

                string fullName = ((string)source).Trim();
                object key = GetKey(fullName, CultureInfo.InvariantCulture);

Trim won't return null, so fullName is going to be a non-null value.

Copy link
Member Author

Choose a reason for hiding this comment

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

If you looked at the old code and traced it if the passed keyToken is null, You'll find that it will throw NullReferenceException at:

                keyToken = keyToken.ToUpper(culture);

But, anyway the passed value isn't null. So, it's okay.

{
return Key.None;
}
Expand Down