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

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

Closed
VasilievSerg opened this issue Nov 22, 2022 · 1 comment · Fixed by #78725
Closed

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

VasilievSerg opened this issue Nov 22, 2022 · 1 comment · Fixed by #78725
Milestone

Comments

@VasilievSerg
Copy link

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?

@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-xml
See info in area-owners.md if you want to be subscribed.

Issue Details

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?

Author: VasilievSerg
Assignees: -
Labels:

area-System.Xml

Milestone: -

@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Nov 22, 2022
@krwq krwq added this to the 8.0.0 milestone Nov 23, 2022
@ghost ghost removed the untriaged New issue has not been triaged by the area owner label Nov 23, 2022
@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Nov 23, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Dec 24, 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