Skip to content

System.ComponentModel.ICustomTypeDescriptor.GetConverter have incorrect nullable annotation #69229

Closed

Description

@jl0pd

Interface System.ComponentModel.ICustomTypeDescriptor have nullable annotations, but method GetConverter is wrongly annotated to return non-null value, while documentation says it could return null:

Returns
A TypeConverter that is the converter for this object, or null if there is no TypeConverter for this object

I propose to mark return value as nullable. It will be breaking change, but people would get NullReferenceException anyway if they wont check for null

Activity

  1. ghost added
    untriagedNew issue has not been triaged by the area owner
    on May 12, 2022
  2. eerhardt commented on May 12, 2022

    @eerhardt
    Member

    @krwq - can you remember a reason why this was annotated this way in #54961?

    Looking through the code, I see some conflicting things:

    1. The following places look like they don't accept null:

    TypeConverter converter = desc.GetConverter();
    if (converter == null) throw new InvalidOperationException(SR.Format(SR.TypeDescriptorProviderError, _node.Provider.GetType().FullName, "GetConverter"));

    converter = desc.GetConverter();
    if (converter == null)
    throw new InvalidOperationException(SR.Format(SR.TypeDescriptorProviderError, _node.Provider.GetType().FullName, "GetConverter"));

    1. These places seem to think returning null is acceptable:

    TypeConverter converter = _primary.GetConverter() ?? _secondary.GetConverter();
    Debug.Assert(converter != null, "Someone should have handled this");
    return converter;

    TypeConverter ICustomTypeDescriptor.GetConverter() => null!;

    TypeConverter ICustomTypeDescriptor.GetConverter()
    {
    return null!;
    }

    TypeConverter ICustomTypeDescriptor.GetConverter() => null!;

  3. added this to the 7.0.0 milestone on May 18, 2022
  4. ghost removed
    untriagedNew issue has not been triaged by the area owner
    on May 18, 2022
  5. added
    breaking-changeIssue or PR that represents a breaking API or functional change over a previous release.
    on May 18, 2022
  6. eerhardt commented on May 18, 2022

    @eerhardt
    Member

    Since this is an interface that is implemented by external code, we should annotate it to be in-line with the documentation. The documentation indicates that null can be returned, so the API should be updated accordingly.

  7. krwq commented on May 19, 2022

    @krwq
    Member

    This seems incorrect - I suspect all internal implementations have returned non-null and I was looking only at the XML docs which was missing null remark (xml docs says only Gets a type converter for this object.) and with all large API surface I missed it.

    I think unless implementation completely disagrees we should change it to match the docs.

  8. added a commit that references this issue on Jul 21, 2022
    a32a110
  9. ghost added
    in-prThere is an active PR which will close this issue when it is merged
    on Jul 21, 2022
  10. added a commit that references this issue on Jul 22, 2022
    c0b9416
  11. ghost removed
    in-prThere is an active PR which will close this issue when it is merged
    on Jul 22, 2022
  12. ghost locked as resolved and limited conversation to collaborators on Aug 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-System.ComponentModelbreaking-changeIssue or PR that represents a breaking API or functional change over a previous release.bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions