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

Attribute.CoreCLR, redundant check #78683

Closed
VasilievSerg opened this issue Nov 22, 2022 · 2 comments · Fixed by #78702
Closed

Attribute.CoreCLR, redundant check #78683

VasilievSerg opened this issue Nov 22, 2022 · 2 comments · Fixed by #78702

Comments

@VasilievSerg
Copy link

The code:

public static Attribute? GetCustomAttribute(ParameterInfo element, Type attributeType, bool inherit)
{
    // ....
    Attribute[] attrib = GetCustomAttributes(element, attributeType, inherit);

    if (attrib == null || attrib.Length == 0) // <=
        return null;

    if (attrib.Length == 0) // <=
        return null;

    if (attrib.Length == 1)
        return attrib[0];

    throw new AmbiguousMatchException(SR.RFLCT_AmbigCust);
}

Link to the sources

The attrib.Length == 0 expression is checked twice. Perhaps it's not an error and just redundant code.
Could you check it?

@dotnet-issue-labeler
Copy link

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@ghost ghost added the untriaged New issue has not been triaged by the area owner label Nov 22, 2022
@ghost
Copy link

ghost commented Nov 22, 2022

Tagging subscribers to this area: @dotnet/area-system-runtime
See info in area-owners.md if you want to be subscribed.

Issue Details

The code:

public static Attribute? GetCustomAttribute(ParameterInfo element, Type attributeType, bool inherit)
{
    // ....
    Attribute[] attrib = GetCustomAttributes(element, attributeType, inherit);

    if (attrib == null || attrib.Length == 0) // <=
        return null;

    if (attrib.Length == 0) // <=
        return null;

    if (attrib.Length == 1)
        return attrib[0];

    throw new AmbiguousMatchException(SR.RFLCT_AmbigCust);
}

Link to the sources

The attrib.Length == 0 expression is checked twice. Perhaps it's not an error and just redundant code.
Could you check it?

Author: VasilievSerg
Assignees: -
Labels:

area-System.Runtime, untriaged

Milestone: -

jkotas added a commit that referenced this issue Nov 22, 2022
@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Nov 22, 2022
jkotas added a commit that referenced this issue Nov 22, 2022
@ghost ghost removed in-pr There is an active PR which will close this issue when it is merged untriaged New issue has not been triaged by the area owner labels Nov 22, 2022
@dotnet dotnet locked as resolved and limited conversation to collaborators Dec 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants