V3131. The expression is checked for compatibility with the type 'A', but is casted to the 'B' type.

The analyzer detected a likely error that has to do with checking if an expression is compatible with one type and casting it to another type inside the body of the conditional statement.

Consider the following example:

if (obj is A)
{
  return (B)obj;
}

The programmer must have made a mistake, since a type conversion like that is very likely to cause a bug. What was actually meant is either to check the expression for type 'B' or cast it to type 'A'.

This is what the correct version could look like:

if (obj is B)
{
  return (B)obj;
}

According to Common Weakness Enumeration, potential errors found by using this diagnostic are classified as CWE-704.

You can look at examples of errors detected by the V3131 diagnostic.


Bugs Found

Checked Projects
384
Collected Errors
13 926
This website uses cookies and other technology to provide you a more personalized experience. By continuing the view of our web-pages you accept the terms of using these files. If you don't want your personal data to be processed, please, leave this site. Learn More →
Accept