Skip to content

DataTable, the result of the new operator is checked for null #78684

Closed

Description

@VasilievSerg

The code:

protected virtual XmlSchema? GetSchema()
{
    if (GetType() == typeof(DataTable))
    {
        return null;
    }
    MemoryStream stream = new MemoryStream();

    XmlWriter writer = new XmlTextWriter(stream, null); // <=
    if (writer != null)    // <=
    {
        (new XmlTreeGen(SchemaFormat.WebService)).Save(this, writer);
    }
    stream.Position = 0;
    return XmlSchema.Read(new XmlTextReader(stream), null);
}

The writer variable is checked for null after the object was created via the new operator. As a result, the writer != null expression is always true.

Is it an error or just redundant code?

Activity

  1. ghost added
    untriaged
    on Nov 22, 2022
  2. ghost added
    in-pr
    on Nov 22, 2022
  3. added this to the 8.0.0 milestone on Nov 23, 2022
  4. ghost removed
    untriaged
    on Nov 23, 2022
  5. ghost removed
    in-pr
    on Nov 23, 2022
  6. ghost locked as resolved and limited conversation to collaborators on Dec 24, 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

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions