To get a trial key
fill out the form below
Team License (standard version)
Enterprise License (extended version)
* By clicking this button you agree to our Privacy Policy statement

** This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.
Request our prices
New License
License Renewal
--Select currency--
USD
EUR
GBP
RUB
* By clicking this button you agree to our Privacy Policy statement

** This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.
To get the licence for your open-source project, please fill out this form
* By clicking this button you agree to our Privacy Policy statement

** This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.
To get the licence for your open-source project, please fill out this form
* By clicking this button you agree to our Privacy Policy statement

** This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.
I am interested to try it on the platforms:
* By clicking this button you agree to our Privacy Policy statement

** This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.
Message submitted.

Your message has been sent. We will email you at


If you haven't received our response, please do the following:
check your Spam/Junk folder and click the "Not Spam" button for our message.
This way, you won't miss messages from our team in the future.

>
>
Examples of errors detected by the V302…

Examples of errors detected by the V3021 diagnostic

Apr 05 2021

V3021. There are two 'if' statements with identical conditional expressions. The first 'if' statement contains method return. This means that the second 'if' statement is senseless.


MonoDevelop

V3021 There are two 'if' statements with identical conditional expressions. The first 'if' statement contains method return. This means that the second 'if' statement is senseless ICSharpCode.NRefactory.CSharp.Refactoring ParameterCanBeDeclaredWithBaseTypeIssue.cs 356


public override void VisitIndexerExpression(
                      IndexerExpression indexerExpression)
{
  ....
  var localResolveResult = context.Resolve(
                             indexerExpression.Target)
                           as LocalResolveResult;
  if (localResolveResult == null)
    return;
  var resolveResult = context.Resolve(indexerExpression);
  if (localResolveResult == null)
    return;
  ....
}

MonoDevelop

V3021 There are two 'if' statements with identical conditional expressions. The first 'if' statement contains method return. This means that the second 'if' statement is senseless ICSharpCode.NRefactory.CSharp CombineQueryExpressions.cs 114


bool TryRemoveTransparentIdentifier(....)
{
  ....
  string nae1Name = ExtractExpressionName(ref nae1);
  if (nae1Name == null)
    return false;

  ....
  string nae2Name = ExtractExpressionName(ref nae2);
  if (nae1Name == null)
    return false;

  ....
}

MonoDevelop

V3021 There are two 'if' statements with identical conditional expressions. The first 'if' statement contains method return. This means that the second 'if' statement is senseless Xwt.WPF DataConverter.cs 217


public static SW.FontWeight
  ToWpfFontWeight (this FontWeight value)
{
  if (value == FontWeight.Thin)
    return SW.FontWeights.Thin;
  if (value == FontWeight.Ultralight)
    return SW.FontWeights.UltraLight;
  if (value == FontWeight.Light)
    return SW.FontWeights.Light;
  if (value == FontWeight.Semilight)
    return SW.FontWeights.Light;
  if (value == FontWeight.Book)  // <=
    return SW.FontWeights.Normal;
  if (value == FontWeight.Medium)
    return SW.FontWeights.Medium;
  if (value == FontWeight.Semibold)
    return SW.FontWeights.SemiBold;
  if (value == FontWeight.Bold)
    return SW.FontWeights.Bold;
  if (value == FontWeight.Ultrabold)
    return SW.FontWeights.UltraBold;
  if (value == FontWeight.Heavy)
    return SW.FontWeights.Black;
  if (value == FontWeight.Ultraheavy)
    return SW.FontWeights.UltraBlack;

  return SW.FontWeights.Normal;
}

public enum FontWeight
{
  /// The thin weight (100)
  Thin = 100,
  /// The ultra light weight (200)
  Ultralight = 200,
  /// The light weight (300)
  Light = 300,
  /// The semi light weight (350)
  Semilight = 350,
  /// The book weight (380)
  Book = 350,
  ....
}

MonoDevelop

V3021 There are two 'if' statements with identical conditional expressions. The first 'if' statement contains method return. This means that the second 'if' statement is senseless Xwt.Gtk ClipboardBackend.cs 86


public override object GetData (TransferDataType type)
{
  if (type == TransferDataType.Text)
    return clipboard.WaitForText ();
  if (type == TransferDataType.Text)
    return clipboard.WaitForImage ();
  ....
}

IronPython and IronRuby

V3021 There are two 'if' statements with identical conditional expressions. The first 'if' statement contains method return. This means that the second 'if' statement is senseless. cPickle.cs 2194


private void LoadNewObj(CodeContext/*!*/ context) {
  PythonTuple args = PopStack() as PythonTuple;
  if (args == null) {
    throw PythonOps.TypeError(
      "expected second argument, got {0}",
      DynamicHelpers.GetPythonType(args));
  }
  PythonType cls = PopStack() as PythonType;
  if (args == null) {
    throw PythonOps.TypeError(
      "expected first argument, got {0}",
      DynamicHelpers.GetPythonType(args));
  }
  ....
}

IronPython and IronRuby

V3021 There are two 'if' statements with identical conditional expressions. The first 'if' statement contains method return. This means that the second 'if' statement is senseless. SourceLocation.cs 156


public static int Compare(SourceLocation left,
                          SourceLocation right) {
  if (left < right) return -1;
  if (right > left) return 1;
  return 0;
}

.NET Compiler Platform ("Roslyn")

V3021 There are two 'if' statements with identical conditional expressions. The first 'if' statement contains method return. This means that the second 'if' statement is senseless InMethodBinder.cs 264


internal static bool ReportConflictWithParameter(....)
{
  ....
  if (newSymbolKind == SymbolKind.Parameter ||
      newSymbolKind == SymbolKind.Local)
  {
    diagnostics.Add(ErrorCode.ERR_LocalSameNameAsTypeParam,
                    newLocation, name);
    return true;
  }
  if (newSymbolKind == SymbolKind.TypeParameter)
  {
    return false;
  }
  if (newSymbolKind == SymbolKind.Parameter ||
      newSymbolKind == SymbolKind.Local)
  {
    diagnostics.Add(ErrorCode.ERR_LocalSameNameAsTypeParam,
                    newLocation, name);
    return true;
  }
  ....
}

Similar errors can be found in some other places:

  • V3021 There are two 'if' statements with identical conditional expressions. The first 'if' statement contains method return. This means that the second 'if' statement is senseless WithLambdaParametersBinder.cs 131

Accord.Net

V3021 There are two 'if' statements with identical conditional expressions. The first 'if' statement contains method return. This means that the second 'if' statement is senseless Accord.Statistics MultivariateEmpiricalDistribution.cs 653


public void Fit(double[][] observations,
                double[] weights,
                MultivariateEmpiricalOptions options)
{
  if (weights != null)
    throw new ArgumentException(
      "This distribution does not support weighted  samples.",
      "weights");
  ....
  if (weights != null)
      weights = inPlace ? weights : (double[])weights.Clone();
  ....
}

Similar errors can be found in some other places:

  • V3021 There are two 'if' statements with identical conditional expressions. The first 'if' statement contains method return. This means that the second 'if' statement is senseless Accord.Statistics MultivariateEmpiricalDistribution.cs 687

Old NASA World Wind (C#)

V3021 There are two 'if' statements with identical conditional expressions. The first 'if' statement contains method return. This means that the second 'if' statement is senseless HtmlEditor.cs 1480


public void LoadUrl(String url)
{
  ....
  if (!isCreated)
  {
    Debug.WriteLine("Doc not created" +
                    iLoadAttempts.ToString());
    if (iLoadAttempts < 2)
    {
      this.bLoadUrlWhenReady = true;
      return;
    }
    else
    {
      throw new HtmlEditorException("Document not created");
    }
  }

  if (!isCreated) return; // <=
  ....
}

Unity3D

V3021 There are two 'if' statements with identical conditional expressions. The first 'if' statement contains method return. This means that the second 'if' statement is senseless UnityEngine.UI StencilMaterial.cs 64


public static Material Add(....)
{
  ....
  if (!baseMat.HasProperty("_StencilReadMask"))
  {
    Debug.LogWarning(".... _StencilReadMask ....", baseMat);
    return baseMat;
  }
  if (!baseMat.HasProperty("_StencilReadMask")) // <=
  {
    Debug.LogWarning(".... _StencilWriteMask ....", baseMat);
    return baseMat;
  }
  ....
}

Mono

V3021 There are two 'if' statements with identical conditional expressions. The first 'if' statement contains method return. This means that the second 'if' statement is senseless corlib-net_4_x String.cs 287


public int LastIndexOfAny (char [] anyOf,
                           int startIndex,
                           int count)
{
  ....
  if (this.m_stringLength == 0)
    return -1;

  ....
  if (this.m_stringLength == 0)
    return -1;

  ....
}

Mono

V3021 There are two 'if' statements with identical conditional expressions. The first 'if' statement contains method return. This means that the second 'if' statement is senseless System.Drawing-net_4_x PrintingServicesUnix.cs 744


private PaperKind GetPaperKind (int width, int height)
{
  ....
  if (width == 1100 && height == 1700)
    return PaperKind.Standard11x17;
  ....
  if (width == 1100 && height == 1700)
    return PaperKind.Tabloid;
  ....
}

Similar errors can be found in some other places:

  • V3021 There are two 'if' statements with identical conditional expressions. The first 'if' statement contains method return. This means that the second 'if' statement is senseless. Mono.Data.Sqlite-net_4_x SQLiteDataReader.cs 270
  • V3021 There are two 'if' statements with identical conditional expressions. The first 'if' statement contains method return. This means that the second 'if' statement is senseless. System.Web-net_4_x HttpUtility.cs 220
  • V3021 There are two 'if' statements with identical conditional expressions. The first 'if' statement contains method return. This means that the second 'if' statement is senseless., System.Design-plaindesign-net_4_x CodeDomComponentSerializationService.cs 562
  • And 1 additional diagnostic messages.

Mono

V3021 There are two 'if' statements with identical conditional expressions. The first 'if' statement contains method return. This means that the second 'if' statement is senseless System.Design-plaindesign-net_4_x CodeDomComponentSerializationService.cs 562


private void SerializeCore (SerializationStore store,
                            object value, bool absolute)
{
  if (value == null)
    throw new ArgumentNullException ("value");
  if (store == null)                            // <=
    throw new ArgumentNullException ("store");

  CodeDomSerializationStore codeDomStore =
    store as CodeDomSerializationStore;
  if (store == null)                            // <=
    throw new InvalidOperationException (
                "store type unsupported");

  codeDomStore.AddObject (value, absolute);
}

SharpDevelop

V3021 There are two 'if' statements with identical conditional expressions. The first 'if' statement contains method return. This means that the second 'if' statement is senseless NamespaceTreeNode.cs 87


public int Compare(SharpTreeNode x, SharpTreeNode y)
{
  ....
  if (typeNameComparison == 0) {
    if (x.Text.ToString().Length < y.Text.ToString().Length)
      return -1;
    if (x.Text.ToString().Length < y.Text.ToString().Length)
      return 1;
  }
  ....
}

Logify Alert Clients

V3021 There are two 'if' statements with identical conditional expressions. The first 'if' statement contains method return. This means that the second 'if' statement is senseless Program.cs 159


bool ValidateConfiguration(SenderConfiguration config) {
  if (String.IsNullOrEmpty(config.Url)) {
      Console.WriteLine("ERROR: service Url not specified");
      return false;
  }
  if (String.IsNullOrEmpty(config.ApiKey)) {
      Console.WriteLine("ERROR: ApiKey not specified");
      return false;
  }
  if (String.IsNullOrEmpty(config.ApiKey)) {
      Console.WriteLine("ERROR: ReportFileName not specified");
      return false;
  }
  ....
}

Unity C# reference source code

V3021 CWE-561 There are two 'if' statements with identical conditional expressions. The first 'if' statement contains method return. This means that the second 'if' statement is senseless CustomScriptAssembly.cs 179


public bool IsCompatibleWith(....)
{
  ....
  if (buildingForEditor)
    return IsCompatibleWithEditor();

  if (buildingForEditor)
    buildTarget = BuildTarget.NoTarget; // Editor
  ....
}

.NET Core Libraries (CoreFX)

V3021 There are two 'if' statements with identical conditional expressions. The first 'if' statement contains method return. This means that the second 'if' statement is senseless XMLDiffLoader.cs 301


private int ReadOldRowData(
  DataSet ds, ref DataTable table, ref int pos, XmlReader row)
{
  ....
  if (table == null)
  {
    row.Skip();
    return -1;
  }
  ....

  if (table == null)
    throw ExceptionBuilder.DiffgramMissingTable(
            XmlConvert.DecodeName(row.LocalName));
  ....
}

OpenCvSharp

V3021 There are two 'if' statements with identical conditional expressions. The first 'if' statement contains method return. This means that the second 'if' statement is senseless InputArray.cs 394


private static MatType EstimateType(Type t)
{
  ....
  if (t == typeof(Vec2b))
    return MatType.CV_8UC2;
  if (t == typeof(Vec3b))
    return MatType.CV_8UC3;
  if (t == typeof(Vec4b))
    return MatType.CV_8UC4;
  if (t == typeof(Vec6b))
    return MatType.CV_8UC(6);
  if (t == typeof(Vec2s))         // <=
    return MatType.CV_16SC2;
  ....
  if (t == typeof(Vec2s))         // <=
    return MatType.CV_32SC2;
  ....
}

OpenCvSharp

V3021 There are two 'if' statements with identical conditional expressions. The first 'if' statement contains method return. This means that the second 'if' statement is senseless Cv2_calib3d.cs 1370


public static double CalibrateCamera(....)
{
  if (objectPoints == null)
    throw new ArgumentNullException(nameof(objectPoints));
  if (objectPoints == null)
    throw new ArgumentNullException(nameof(objectPoints));
  ....
}

Also see V3022

Similar errors can be found in some other places:

  • V3021 There are two 'if' statements with identical conditional expressions. The first 'if' statement contains method return. This means that the second 'if' statement is senseless Cv2_calib3d.cs 1444

Emby

V3021 There are two 'if' statements with identical conditional expressions. The first 'if' statement contains method return. This means that the second 'if' statement is senseless SkiaEncoder.cs 537


public string EncodeImage(string inputPath,
                          DateTime dateModified,
                          string outputPath,
                          bool autoOrient,
                          ImageOrientation? orientation,
                          int quality,
                          ImageProcessingOptions options,
                          ImageFormat selectedOutputFormat)
{
  if (string.IsNullOrWhiteSpace(inputPath))
  {
      throw new ArgumentNullException("inputPath");
  }
  if (string.IsNullOrWhiteSpace(inputPath))
  {
      throw new ArgumentNullException("outputPath");
  }
  ....
}

Nethermind

V3021 There are two 'if' statements with identical conditional expressions. The first 'if' statement contains method return. This means that the second 'if' statement is senseless Nethermind.Network.Benchmark InFlowBenchmarks.cs 55


public void Setup()
{
  if (_decoderBuffer.ReadableBytes > 0)
  {
    throw new Exception("decoder buffer");
  }

  if (_decoderBuffer.ReadableBytes > 0)
  {
    throw new Exception("decoder buffer");
  }
  ....
}

ONLYOFFICE Community Server

V3021 There are two 'if' statements with identical conditional expressions. The first 'if' statement contains method return. This means that the second 'if' statement is senseless WikiEngine.cs 688


private static LinkType CheckTheLink(string str, out string sLink)
{
    sLink = string.Empty;

    if (string.IsNullOrEmpty(str))
        return LinkType.None;

    if (str[0] == '[')
    {
        sLink = str.Trim("[]".ToCharArray()).Split('|')[0].Trim();
    }
    else if (....)
    {
        sLink = str.Split('|')[0].Trim();
    }
    sLink = sLink.Split('#')[0].Trim();    // <=
    if (string.IsNullOrEmpty(str))         // <=
        return LinkType.None;

    if (sLink.Contains(":"))
    {
      ....
    }
    ....
}

Popular related articles
Appreciate Static Code Analysis!

Date: Oct 16 2017

Author: Andrey Karpov

I am really astonished by the capabilities of static code analysis even though I am one of the developers of PVS-Studio analyzer myself. The tool surprised me the other day as it turned out to be sma…
PVS-Studio for Java

Date: Jan 17 2019

Author: Andrey Karpov

In the seventh version of the PVS-Studio static analyzer, we added support of the Java language. It's time for a brief story of how we've started making support of the Java language, how far we've co…
The Evil within the Comparison Functions

Date: May 19 2017

Author: Andrey Karpov

Perhaps, readers remember my article titled "Last line effect". It describes a pattern I've once noticed: in most cases programmers make an error in the last line of similar text blocks. Now I want t…
Free PVS-Studio for those who develops open source projects

Date: Dec 22 2018

Author: Andrey Karpov

On the New 2019 year's eve, a PVS-Studio team decided to make a nice gift for all contributors of open-source projects hosted on GitHub, GitLab or Bitbucket. They are given free usage of PVS-Studio s…
The way static analyzers fight against false positives, and why they do it

Date: Mar 20 2017

Author: Andrey Karpov

In my previous article I wrote that I don't like the approach of evaluating the efficiency of static analyzers with the help of synthetic tests. In that article, I give the example of a code fragment…
Characteristics of PVS-Studio Analyzer by the Example of EFL Core Libraries, 10-15% of False Positives

Date: Jul 31 2017

Author: Andrey Karpov

After I wrote quite a big article about the analysis of the Tizen OS code, I received a large number of questions concerning the percentage of false positives and the density of errors (how many erro…
Technologies used in the PVS-Studio code analyzer for finding bugs and potential vulnerabilities

Date: Nov 21 2018

Author: Andrey Karpov

A brief description of technologies used in the PVS-Studio tool, which let us effectively detect a large number of error patterns and potential vulnerabilities. The article describes the implementati…
The Last Line Effect

Date: May 31 2014

Author: Andrey Karpov

I have studied many errors caused by the use of the Copy-Paste method, and can assure you that programmers most often tend to make mistakes in the last fragment of a homogeneous code block. I have ne…
How PVS-Studio Proved to Be More Attentive Than Three and a Half Programmers

Date: Oct 22 2018

Author: Andrey Karpov

Just like other static analyzers, PVS-Studio often produces false positives. What you are about to read is a short story where I'll tell you how PVS-Studio proved, just one more time, to be more atte…
Static analysis as part of the development process in Unreal Engine

Date: Jun 27 2017

Author: Andrey Karpov

Unreal Engine continues to develop as new code is added and previously written code is changed. What is the inevitable consequence of ongoing development in a project? The emergence of new bugs in th…

Comments (0)

Next comments

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.
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