Examples of errors detected by the V3003 diagnostic.

V3003. The use of 'if (A) {...} else if (A) {...}' pattern was detected. There is a probability of logical error presence.


SharpDevelop

V3003 The use of 'if (A) {...} else if (A) {...}' pattern was detected. There is a probability of logical error presence. Check lines: 773, 798. DockableContent.cs 773


protected override bool CanExecuteCommand(ICommand command)
{
  ....
  }
  else if (command == DockableContentCommands.ShowAsDocument)
  {
    if (State == DockableContentState.Document)
    {
      return false;
    }
  }
  ....
  else if (command == DockableContentCommands.ShowAsDocument)
  {
    if (State == DockableContentState.Document)
    {
      return false;
    }
  }
  ....
}

Microsoft Code Contracts

V3003 The use of 'if (A) {...} else if (A) {...}' pattern was detected. There is a probability of logical error presence. Check lines: 1200, 1210. OutputPrettyCS.cs 1200


public enum TypeConstraint
{
  NONE,
  CLASS,     // <=
  STRUCT,    // <=
  BASECLASS,
}

public void Output(OutputHelper oh)
{
  Contract.Requires(oh != null);

  oh.Output("where ", false);
  mParent.OutputName(oh);
  oh.Output(" : ", false);
  //** base class
  bool comma = false;
  if (mTypeConstraint == TypeConstraint.CLASS)       // <=
  {
    oh.Output("class", false);
    comma = true;
  }
  else if (mTypeConstraint == TypeConstraint.STRUCT)
  {
    oh.Output("struct", false);
    comma = true;
  }
  else if (mTypeConstraint == TypeConstraint.CLASS)  // <=
  {
    oh.Output(mClassConstraint, false);
    comma = true;
  }
}

Xamarin.Forms

V3003 The use of 'if (A) {...} else if (A) {...}' pattern was detected. There is a probability of logical error presence. Check lines: 28, 30. Xamarin.Forms.Platform.Android SwitchRenderer.cs 28


public override SizeRequest
GetDesiredSize(int widthConstraint, int heightConstraint)
{
  ....
  int width = widthConstraint;
  if (widthConstraint <= 0)
    width = (int)Context.GetThemeAttributeDp(
                  global::Android.Resource
                                 .Attribute
                                 .SwitchMinWidth);
  else if (widthConstraint <= 0)
    width = 100;
  ....
}

Identical errors can be found in some other places:

  • V3003 The use of 'if (A) {...} else if (A) {...}' pattern was detected. There is a probability of logical error presence. Check lines: 26, 28. Xamarin.Forms.Platform.Android SwitchRenderer.cs 26

WPF samples by Microsoft

V3003 The use of 'if (A) {...} else if (A) {...}' pattern was detected. There is a probability of logical error presence. Check lines: 418, 422. txtserializerwriter.cs 418


public int Compare(GlyphRun a, GlyphRun b)
{
  ....
  if (aPoint.Y > bPoint.Y)      // <=
  {
    return -1;
  }
  else if (aPoint.Y > bPoint.Y) // <=
  {
    result = 1;
  }
  else if (aPoint.X < bPoint.X)
  {
    result = -1;
  }
  else if (aPoint.X > bPoint.X)
  {
    result = 1;
  }
  ....
}

Old NASA World Wind (C#)

V3003 The use of 'if (A) {...} else if (A) {...}' pattern was detected. There is a probability of logical error presence. Check lines: 2111, 2197. KMLImporter.cs 2111


private static void WebUpdate(....)
{
  ....
  if (ver != version)          // <=
  {
    ....
  }
  else if (ver != version)    // <=
  {
    ....
  }
}

Old NASA World Wind (C#)

V3003 The use of 'if (A) {...} else if (A) {...}' pattern was detected. There is a probability of logical error presence. Check lines: 4503, 4607. GPSTracker.cs 4503

V3003 The use of 'if (A) {...} else if (A) {...}' pattern was detected. There is a probability of logical error presence. Check lines: 4527, 4530. GPSTracker.cs 4527


public bool LoadSettings(....)
{
 ....
 if (bSet)
 {
   while(true)
   {
     line = sr.ReadLine();
     if (line==null || line.StartsWith("END UI CONTROLS"))
       break;
     ....
     if (line.StartsWith("comboBoxAPRSInternetServer=")) // <=
       ....
     else
     ....
     if (line.StartsWith("checkBoxNoDelay="))            // <=
       ....
     else
     if (line.StartsWith("checkBoxNoDelay="))            // <=
       ....
     ....
     else
     if (line.StartsWith("comboBoxAPRSInternetServer=")) // <=
     ....
   }
   ....
 }
 ....
}

Mono

V3003 The use of 'if (A) {...} else if (A) {...}' pattern was detected. There is a probability of logical error presence. Check lines: 597, 599. Hwnd.cs 597


public Point MenuOrigin {
  get {
    ....
    if (this.title_style == TitleStyle.Normal)  {        // <=
      pt.Y += caption_height;
    } else if (this.title_style == TitleStyle.Normal)  { // <=
      pt.Y += tool_caption_height;
    }
    ....
}

Media Portal 2

V3003 The use of 'if (A) {...} else if (A) {...}' pattern was detected. There is a probability of logical error presence. Check lines: 452, 462. Scanner.cs 452


private object ScanNumber()
{
  ....
  if (style == NumberStyles.Integer)
  {
    int ivalue;
    if (int.TryParse(num, out ivalue))
      return ivalue;
    ....
  }
  else if (style == NumberStyles.Integer) // <=
  {
    return double.Parse(num);
  }
  ....
}

The condition of both "if" statements is completely equivalent, so the second "if" body will never been executed.


PascalABC.NET

V3003 The use of 'if (A) {...} else if (A) {...}' pattern was detected. There is a probability of logical error presence. Check lines: 597, 631. ParserTools SyntaxTreeComparer.cs 597


public void CompareInternal(....)
{
  ....
  if (left is ident)
    CompareInternal(left as ident, right as ident);
  ....
  else if (left is int64_const)
    CompareInternal(left as int64_const, right as int64_const);
  ....
  else if (left is int64_const)
    CompareInternal(left as int64_const, right as int64_const);
  ....
}

Identical errors can be found in some other places:

  • V3003 The use of 'if (A) {...} else if (A) {...}' pattern was detected. There is a probability of logical error presence. Check lines: 1599, 1611. ParserTools SyntaxTreeComparer.cs 1599
  • V3003 The use of 'if (A) {...} else if (A) {...}' pattern was detected. There is a probability of logical error presence. Check lines: 1611, 1615. ParserTools SyntaxTreeComparer.cs 1611
  • V3003 The use of 'if (A) {...} else if (A) {...}' pattern was detected. There is a probability of logical error presence. Check lines: 103, 209. SyntaxVisitors SimplePrettyPrinterVisitor.cs 103


Do you make errors in the code?

Check your code
with PVS-Studio

Static code analysis
for C, C++ and C#

goto PVS-Studio;