Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

False positive on a contant value when using GeneratedCodeAttribute #479

Open
GerbrandStap opened this issue Jan 24, 2017 · 0 comments
Open

Comments

@GerbrandStap
Copy link

Analyzing the following code:

[System.CodeDom.Compiler.GeneratedCodeAttribute("","")]
public class GeneratedClass
{
}

public class Test
{
	private GeneratedClass _cachedItem;

	public GeneratedClass Item
	{
		get
		{
			if( this._cachedItem == null )
			{
				this._cachedItem = new GeneratedClass();
			}
			return this._cachedItem;
		}
	}
}

Produces the error:

CodeContracts: warning: The Boolean condition this._cachedItem == null always evaluates to a constant value. If it (or its negation) appear in the source code, you may have some dead code or redundant check

When the GeneratedCodeAttribute attribute is removed, the error no longer occurs. The attribute gets added by the xsd tool in our case, so it is generated code and we'd rather not have to remove the attribute,

We use Code Contracts 1.10.20606.1.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant