Unicorn with delicious cookie
Nous utilisons des cookies pour améliorer votre expérience de navigation. En savoir plus
Accepter
to the top
>
>
>
Examples of errors detected by the V300…

Examples of errors detected by the V3004 diagnostic

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();
    }
    ....
}

DotNetNuke

V3004 The 'then' statement is equivalent to the 'else' statement. DNNListEditControl.cs 380


protected override void RenderEditMode(HtmlTextWriter writer)
{
  ....
  // Add the Not Specified Option
  if (this.ValueField == ListBoundField.Text)
  {
    writer.AddAttribute(HtmlTextWriterAttribute.Value, Null.NullString);
  }
  else
  {
    writer.AddAttribute(HtmlTextWriterAttribute.Value, Null.NullString);
  }
  ....
}

DotNetNuke

V3004 The 'then' statement is equivalent to the 'else' statement. Search.ascx.cs 432


protected void ExecuteSearch(string searchText, string searchType)
{
  ....
  if (Host.UseFriendlyUrls)
  {
    this.Response.Redirect(this._navigationManager.NavigateURL(searchTabId));
  }
  else
  {
    this.Response.Redirect(this._navigationManager.NavigateURL(searchTabId));
  }
  ....
}

Umbraco

V3004 The 'then' statement is equivalent to the 'else' statement. UrlProviderExtensions.cs 274


private static async Task<Attempt<UrlInfo>> DetectCollisionAsync(....)
{
  ....
  if (pcr.IgnorePublishedContentCollisions)
  {
    logger.LogDebug(logMsg, url, uri, culture);
  }
  else
  {
    logger.LogDebug(logMsg, url, uri, culture);
  }
}

Barotrauma

V3004 The 'then' statement is equivalent to the 'else' statement. ServerEntityEventManager.cs 314


public void Write(Client client, IWriteMessage msg,
                  out List<NetEntityEvent> sentEvents)
{
  List<NetEntityEvent> eventsToSync = null;
  if (client.NeedsMidRoundSync)
  {
    eventsToSync = GetEventsToSync(client);
  }
  else
  {
    eventsToSync = GetEventsToSync(client);
  }
  ....
}

Orleans

V3004 The 'then' statement is equivalent to the 'else' statement. TransactionalStateStorageTestRunner.cs 327


public virtual async Task ConfirmOneAndCancelOne(bool useTwoSteps = false,
                                                 bool reverseOrder = false)
{
  ....
  if (useTwoSteps)
  {
    if (reverseOrder)                                                 // <=
    {
      etag = await stateStorage.Store(etag, metadata,
                                      emptyPendingStates, 1, null);

      _ = await stateStorage.Store(etag, metadata,
                                         emptyPendingStates, null, 1);
    }
    else
    {
      etag = await stateStorage.Store(etag, metadata,
                                      emptyPendingStates, 1, null);

      _ = await stateStorage.Store(etag, metadata,
                                   emptyPendingStates, null, 1);
    }
  }
  else
  {
    _ = await stateStorage.Store(etag, metadata,
                                 emptyPendingStates, 1, 1);
  }
  ....
}

AvalonStudio

V3004 The 'then' statement is equivalent to the 'else' statement. InvocationContext.cs 400


private static Signature BuildSignature(IMethodSymbol symbol)
{
  ....
  var returnTypeInfo = CheckForStaticExtension.GetReturnType(symbol);
  if(returnTypeInfo.HasValue)
  {
    if(returnTypeInfo.Value.inbuilt)
    {
      signature.BuiltInReturnType = returnTypeInfo.Value.name;
    }
    else
    {
      signature.ReturnType = returnTypeInfo.Value.name;
    }
  }
  signature.Parameters = symbol.Parameters.Select(parameter =>
  {
    var info = CheckForStaticExtension.GetReturnType(parameter);
    ....
    if(info.HasValue)
    {
      if(info.Value.inbuilt)
      {
        result.BuiltInType = info.Value.name;   // <=
      }
      else
      {
        result.BuiltInType = info.Value.name;   // <=
      }
    }
    ....
  }).ToList();
  ....
}

close form

Remplissez le formulaire ci‑dessous en 2 étapes simples :

Vos coordonnées :

Étape 1
Félicitations ! Voici votre code promo !

Type de licence souhaité :

Étape 2
Team license
Enterprise licence
** En cliquant sur ce bouton, vous déclarez accepter notre politique de confidentialité
close form
Demandez des tarifs
Nouvelle licence
Renouvellement de licence
--Sélectionnez la devise--
USD
EUR
* En cliquant sur ce bouton, vous déclarez accepter notre politique de confidentialité

close form
La licence PVS‑Studio gratuit pour les spécialistes Microsoft MVP
close form
Pour obtenir la licence de votre projet open source, s’il vous plait rempliez ce formulaire
* En cliquant sur ce bouton, vous déclarez accepter notre politique de confidentialité

close form
I want to join the test
* En cliquant sur ce bouton, vous déclarez accepter notre politique de confidentialité

close form
check circle
Votre message a été envoyé.

Nous vous répondrons à


Si l'e-mail n'apparaît pas dans votre boîte de réception, recherchez-le dans l'un des dossiers suivants:

  • Promotion
  • Notifications
  • Spam