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.
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 V300…

Examples of errors detected by the V3004 diagnostic

April 5, 2021

V3004. The 'then' statement is equivalent to the 'else' statement.


Umbraco

V3004 The 'then' statement is equivalent to the 'else' statement. TinyMCE.cs 170


public TinyMCE(IData Data, string Configuration)
{
  ....
  if (p.Alias.StartsWith("."))
    styles += p.Text + "=" + p.Alias;
  else
    styles += p.Text + "=" + p.Alias;
  ....
}

SharpDevelop

V3004 The 'then' statement is equivalent to the 'else' statement. Editor.cs 225


new public bool Enabled {
  get { return base.Enabled; }
  set {
    if (this.InvokeRequired) {
      base.Enabled = this.VScrollBar.Enabled =
      this.hexView.Enabled =this.textView.Enabled =
      this.side.Enabled = this.header.Enabled = value;
    } else {
      base.Enabled = this.VScrollBar.Enabled =
      this.hexView.Enabled = this.textView.Enabled =
      this.side.Enabled = this.header.Enabled = value;
    }
  }
}

Microsoft Code Contracts

V3004 The 'then' statement is equivalent to the 'else' statement. Metadata.cs 2602


private void SerializeFieldRvaTable(....)
{
  ....
  switch (row.TargetSection){
    case PESection.SData:
    case PESection.TLS:
      Fixup fixup = new Fixup();
      fixup.fixupLocation = writer.BaseStream.Position;
      fixup.addressOfNextInstruction = row.RVA;
      if (row.TargetSection == PESection.SData){
        sdataFixup.nextFixUp = fixup;   // <=
        sdataFixup = fixup;             // <=
      }else{
        sdataFixup.nextFixUp = fixup;   // <=
        sdataFixup = fixup;             // <=
      }
      writer.Write((int)0);
      break;
  ....
}

Similar errors can be found in some other places:

  • V3004 The 'then' statement is equivalent to the 'else' statement. Nodes.cs 6698
  • V3004 The 'then' statement is equivalent to the 'else' statement. Nodes.cs 6713
  • V3004 The 'then' statement is equivalent to the 'else' statement. WarningSuggestionLinkOutput.cs 108
  • And 1 additional diagnostic messages.

.NET Core Libraries (CoreFX)

V3004 The 'then' statement is equivalent to the 'else' statement. XmlSerializationWriterILGen.cs 1213


private void WriteMember(...., TypeDesc memberTypeDesc, ....)
{
  ....
  if (memberTypeDesc.IsArray)
  {
    LocalBuilder localI = ilg.DeclareOrGetLocal(...., iVar);
    ilg.For(localI, 0, ilg.GetLocal(aVar));
  }
  else
  {
    LocalBuilder localI = ilg.DeclareOrGetLocal(...., iVar);
    ilg.For(localI, 0, ilg.GetLocal(aVar));
  }
  ....
}

.NET Core Libraries (CoreFX)

V3004 The 'then' statement is equivalent to the 'else' statement. SqlUtil.cs 93


internal static void ContinueTask(....)
{
  ....
  if (connectionToDoom != null || connectionToAbort != null)
  {
    try
    {
      onSuccess();
    }
    catch (Exception e)
    {
      completion.SetException(e);
    }
  }
  else
  { // no connection to doom - reliability section not required
    try
    {
      onSuccess();
    }
    catch (Exception e)
    {
      completion.SetException(e);
    }
  }
  ....
}

.NET Compiler Platform ("Roslyn")

V3004 The 'then' statement is equivalent to the 'else' statement. GetSemanticInfoTests.cs 2269


public void IndexerMemberRace()
{
  ....
  for (int i = 0; i < 20; i++)
  {
    ....
    if (i % 2 == 0)
    {
      thread1.Start();
      thread2.Start();
    }
    else
    {
      thread1.Start();
      thread2.Start();
    }
    ....
  }
  ....
}

Sony ATF

V3004 The 'then' statement is equivalent to the 'else' statement. Atf.Gui.WinForms.vs2010 DropDescriptionHelper.cs 199


public static void DefaultGiveFeedback(IComDataObject data,
                                       GiveFeedbackEventArgs e)
{
  ....
  if (setDefaultDropDesc &&
      (DropImageType)e.Effect != currentType)
  {
    if (e.Effect != DragDropEffects.None)
    {
      SetDropDescription(data,
        (DropImageType)e.Effect, e.Effect.ToString(), null);
    }
    else
    {
      SetDropDescription(data,
        (DropImageType)e.Effect, e.Effect.ToString(), null);
    }
    ....
  }
}

Space Engineers

V3004 The 'then' statement is equivalent to the 'else' statement. Sandbox.Game MyAgentBot.cs 260


private void StartRespawn()
{
  m_lastCountdownTime = MySandboxGame
                          .TotalGamePlayTimeInMilliseconds;
  if (m_removeAfterDeath)
    m_deathCountdownMs = AgentDefinition.RemoveTimeMs;
  else
    m_deathCountdownMs = AgentDefinition.RemoveTimeMs;
}

Space Engineers

V3004 The 'then' statement is equivalent to the 'else' statement. Sandbox.Game MyNavigationTriangle.cs 189


private static bool IsTriangleDangerous(int triIndex)
{
  if (MyPerGameSettings.NavmeshPresumesDownwardGravity)
  {
    return triIndex == -1;
  }
  else
  {
    return triIndex == -1;
  }
}

Space Engineers

V3004 The 'then' statement is equivalent to the 'else' statement. Sandbox.Game MyThrust.cs 149


public void UpdateLight()
{
  ....
  if (((MyCubeGrid)Parent).GridSizeEnum == MyCubeSize.Large)
    Light.GlareIntensity = 0.5f + length * 2;
  else
    Light.GlareIntensity = 0.5f + length * 2;
  ....
}

Mono

V3004 The 'then' statement is equivalent to the 'else' statement. System.Windows.Forms-net_4_x TextBoxTextRenderer.cs 79


public static void DrawText (....)
{
  ....
  if (showNonPrint)
    TextRenderer.DrawTextInternal (g, text, font,
      new Rectangle (new Point ((int)x, (int)y), max_size),
      color,
      TextFormatFlags.NoPadding |
      TextFormatFlags.NoPrefix, false);
  else
    TextRenderer.DrawTextInternal (g, text, font,
      new Rectangle (new Point ((int)x, (int)y), max_size),
      color,
      TextFormatFlags.NoPadding |
      TextFormatFlags.NoPrefix, false);
  ....
}

PascalABC.NET

V3004 The 'then' statement is equivalent to the 'else' statement. VisualPascalABCNET CodeCompletionWindow.cs 204


public void HandleMouseWheel(....)
{
  ....
  if (System.Windows.Forms.SystemInformation.
      MouseWheelScrollLines > 0) {
    newValue = this.vScrollBar.Value -
      (control.TextEditorProperties.MouseWheelScrollDown ? 1 :
       -1) * multiplier;
  } else {
    newValue = this.vScrollBar.Value -
      (control.TextEditorProperties.MouseWheelScrollDown ? 1 :
       -1) * multiplier;
  }
  ....
}

Similar errors can be found in some other places:

  • V3004 The 'then' statement is equivalent to the 'else' statement. NETGenerator NETGenerator.cs 439
  • V3004 The 'then' statement is equivalent to the 'else' statement. NETGenerator NETGenerator.cs 2338
  • V3004 The 'then' statement is equivalent to the 'else' statement. NETGenerator NETGenerator.cs 4062
  • And 7 additional diagnostic messages.

Infer.NET

V3004 The 'then' statement is equivalent to the 'else' statement. Runtime RegexpTreeBuilder.cs 1080


public int Compare(Pair<int, int> x, Pair<int, int> y)
{
  if (x.First < y.First)
  {
    if (x.Second >= y.Second)
    {
      return 1;
    }
    else
    {
      return 1;
    }
  }
  else if (x.First > y.First)
  {
    if (x.Second <= y.Second)
    {
      return -1;
    }
    else
    {
      return -1;
    }
  }
  ....
}

Similar errors can be found in some other places:

  • V3004 The 'then' statement is equivalent to the 'else' statement. Runtime RegexpTreeBuilder.cs 1093

FastReport

V3004 The 'then' statement is equivalent to the 'else' statement. HtmlTextRenderer.cs 2092


public override Run Split(float availableWidth, out Run secondPart)
{
  ....
  if (r.Width > availableWidth)
  {
    List<CharWithIndex> list = new List<CharWithIndex>();
    for (int i = point; i < size; i++)
      list.Add(chars[i]);
    secondPart = new RunText(renderer, word, style, list,
                             left + r.Width, charIndex);
    list.Clear();
    for (int i = 0; i < point; i++)
        list.Add(chars[i]);
    r = new RunText(renderer, word, style, list, left, charIndex);

    return r;
  }
  else
  {
    List<CharWithIndex> list = new List<CharWithIndex>();
    for (int i = point; i < size; i++)
        list.Add(chars[i]);
    secondPart = new RunText(renderer, word, style, list,
                             left + r.Width, charIndex);
    list.Clear();
    for (int i = 0; i < point; i++)
        list.Add(chars[i]);
    r = new RunText(renderer, word, style, list, left, charIndex);
    return r;
  }
  ....
}

.NET Core Libraries (CoreFX)

V3004 The 'then' statement is equivalent to the 'else' statement. DirectorySearcher.cs 629


private SearchResultCollection FindAll(bool findMoreThanOne)
{
  searchResult = null;

  DirectoryEntry clonedRoot = null;
  if (_assertDefaultNamingContext == null)
  {
    clonedRoot = SearchRoot.CloneBrowsable();
  }
  else
  {
    clonedRoot = SearchRoot.CloneBrowsable();
  }
  ....
}

.NET Core Libraries (CoreFX)

V3004 The 'then' statement is equivalent to the 'else' statement. QueryOutputWriterV1.cs 242


public override void WriteBase64(byte[] buffer, int index, int count)
{
  if (!_inAttr && (_inCDataSection || StartCDataSection()))
    _wrapped.WriteBase64(buffer, index, count);
  else
    _wrapped.WriteBase64(buffer, index, count);
}

AvaloniaUI

V3004 The 'then' statement is equivalent to the 'else' statement. DataGridSortDescription.cs 235


public override
  IOrderedEnumerable<object> ThenBy(IOrderedEnumerable<object> seq)
{
  if (_descending)
  {
    return seq.ThenByDescending(o => GetValue(o), InternalComparer);
  }
  else
  {
    return seq.ThenByDescending(o => GetValue(o), InternalComparer);
  }
}

Emby

V3004 The 'then' statement is equivalent to the 'else' statement. SqliteItemRepository.cs 5648


private QueryResult<Tuple<BaseItem, ItemCounts>> GetItemValues(....)
{
  ....
  if (typesToCount.Length == 0)
  {
    whereText += " And CleanName In (Select CleanValue
                                    from ItemValues where "
    + typeClause + " AND ItemId in (select guid from TypedBaseItems"
    + innerWhereText + "))";
  }
  else
  {
    //whereText += " And itemTypes not null";
    whereText += " And CleanName In (Select CleanValue
                                    from ItemValues where "
    + typeClause + " AND ItemId in (select guid from TypedBaseItems"
    + innerWhereText + "))";
  }
  ....
}

RunUO

V3004 The 'then' statement is equivalent to the 'else' statement. Serialization.cs 1571


public override void WriteDeltaTime( DateTime value )
{
  ....
  try
  {
    d = new TimeSpan( ticks-now );
  }
  catch
  {
    if( ticks < now )
      d = TimeSpan.MaxValue;
    else
      d = TimeSpan.MaxValue;
  }
  ....
}

Similar errors can be found in some other places:

  • V3004 The 'then' statement is equivalent to the 'else' statement. Item.cs 2103
  • V3004 The 'then' statement is equivalent to the 'else' statement. Serialization.cs 383

Nethermind

V3004 The 'then' statement is equivalent to the 'else' statement. Nethermind.BeaconNode BeaconNodeFacade.cs 177


public async Task<ApiResponse>
PublishBlockAsync(SignedBeaconBlock signedBlock,
                  CancellationToken cancellationToken)
{
  bool acceptedLocally = false;
  ....
  if (acceptedLocally)
  {
    return new ApiResponse(StatusCode.Success);
  }
  else
  {
    return new ApiResponse(StatusCode.Success);
  }
  ....
}

Similar errors can be found in some other places:

  • V3004 The 'then' statement is equivalent to the 'else' statement. Nethermind.Overseer.Test TestBuilder.cs 46

QuantConnect Lean

V3004 The 'then' statement is equivalent to the 'else' statement. FuturesExpiryFunctions.cs 1561


public static readonly Dictionary<....>
  FuturesExpiryDictionary = new Dictionary<....>()
{
  ....
  if (twoMonthsPriorToContractMonth.Month == 2)
  {
    lastBusinessDay = FuturesExpiryUtilityFunctions
                      .NthLastBusinessDay(twoMonthsPriorToContractMonth, 1);
  }
  else
  {
    lastBusinessDay = FuturesExpiryUtilityFunctions
                      .NthLastBusinessDay(twoMonthsPriorToContractMonth, 1);
  }
  ....
}

ONLYOFFICE Community Server

V3004 The 'then' statement is equivalent to the 'else' statement. SelectelStorage.cs 461


public override string[] ListFilesRelative(....)
{
    var paths = new List<String>();
    var client = GetClient().Result;

    if (recursive)
    {
        paths = client.GetContainerFilesAsync(_private_container, int.MaxValue,
            null, MakePath(domain, path)).Result.Select(x => x.Name).ToList();
    }
    else
    {
        paths = client.GetContainerFilesAsync(_private_container, int.MaxValue,
            null, MakePath(domain, path)).Result.Select(x => x.Name).ToList();
    }
    ....
}

Popular related articles
The way static analyzers fight against false positives, and why they do it

Date: 03.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…
Free PVS-Studio for those who develops open source projects

Date: 12.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 Evil within the Comparison Functions

Date: 05.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…
Static analysis as part of the development process in Unreal Engine

Date: 06.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…
The Last Line Effect

Date: 05.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…
PVS-Studio for Java

Date: 01.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…
PVS-Studio ROI

Date: 01.30.2019

Author: Andrey Karpov

Occasionally, we're asked a question, what monetary value the company will receive from using PVS-Studio. We decided to draw up a response in the form of an article and provide tables, which will sho…
How PVS-Studio Proved to Be More Attentive Than Three and a Half Programmers

Date: 10.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…
The Ultimate Question of Programming, Refactoring, and Everything

Date: 04.14.2016

Author: Andrey Karpov

Yes, you've guessed correctly - the answer is "42". In this article you will find 42 recommendations about coding in C++ that can help a programmer avoid a lot of errors, save time and effort. The au…
Appreciate Static Code Analysis!

Date: 10.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…

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