RefactoringEssentials icon indicating copy to clipboard operation
RefactoringEssentials copied to clipboard

"Add null check" breaks execution flow

Open nick-morhun opened this issue 7 years ago • 0 comments

The "Add null check" C# refactoring results in an unwanted change of execution flow. In this example

bool b = true;
object o = null;
if (b)
{
	int i = (int)o;
}
else
{
	/* else clause */
}

it changes code to

bool b = true;
object o = null;
if (b && (o != null))
{
	int i = (int)o;
}
else
{
	/* else clause */
}

which in case o is null results in execution of the 'else' clause where it was not supposed to execute.

nick-morhun avatar Nov 28 '17 10:11 nick-morhun