Examples of errors detected by the V3027 diagnostic.

V3027. The variable was utilized in the logical expression before it was verified against null in the same logical expression.


.NET Core Libraries (CoreFX)

V3027 The variable 'start.BaseMapping' was utilized in the logical expression before it was verified against null in the same logical expression. Mappings.cs 598


internal void SetSequence()
{
  if (TypeDesc.IsRoot)
      return;

  StructMapping start = this;

  // find first mapping that does not have the sequence set
  while (!start.BaseMapping.IsSequence &&          // <=
          start.BaseMapping != null    &&          // <=
         !start.BaseMapping.TypeDesc.IsRoot)
      start = start.BaseMapping;
  ....
}

MonoDevelop

V3027 The variable 'oldNode' was utilized in the logical expression before it was verified against null in the same logical expression. MonoDevelop.HexEditor RedBlackTree.cs 167


void Replace (RedBlackTreeNode oldNode, RedBlackTreeNode newNode)
{
  ....
  if (oldNode.parent.left == oldNode ||
      oldNode == null && oldNode.parent.left == null)
  ....
}

IronPython and IronRuby

V3027 The variable 'result' was utilized in the logical expression before it was verified against null in the same logical expression. MutableStringOps.cs 1097


public static MutableString ChompInPlace(....) {
  MutableString result = InternalChomp(self, separator);
  if (result.Equals(self) || result == null) {
    self.RequireNotFrozen();
    return null;
  }
  ....
}

.NET Compiler Platform ("Roslyn")

V3027 The variable 'newType' was utilized in the logical expression before it was verified against null in the same logical expression. AbstractSpeculationAnalyzer.cs 383


private static bool SymbolsAreCompatibleCore(....)
{
  ....
  var type = methodSymbol.ContainingType;
  var newType = newMethodSymbol.ContainingType;
  if ((type != null && type.IsEnumType() &&
       type.EnumUnderlyingType != null &&
       type.EnumUnderlyingType.SpecialType ==
         newType.SpecialType) ||
      (newType != null && newType.IsEnumType() &&
       newType.EnumUnderlyingType != null &&
       newType.EnumUnderlyingType.SpecialType ==
         type.SpecialType))
  {
    return true;
  }
  ....
}

Space Engineers

V3027 The variable 'MySession.ControlledEntity' was utilized in the logical expression before it was verified against null in the same logical expression. Sandbox.Game MyHudWarning.cs 415


private static bool EnergyCritWarningMethod(out MyGuiSounds cue,
                                            out MyStringId text)
{
  ....
  if (MySession.ControlledEntity.Entity is MyCharacter ||
      MySession.ControlledEntity == null)
  ....
}

Mono

V3027 The variable 'm.DeclaringType' was utilized in the logical expression before it was verified against null in the same logical expression. Mono.CodeContracts-net_4_x ContractNodes.cs 211


private bool IsContractMethod (string methodName,
                               Method m,
                               out TypeNode genericArgument)
{
  ....
  return m.Name != null && m.Name == methodName &&
    (m.DeclaringType.Equals (this.ContractClass)       // <=
     || (m.Parameters    != null &&
         m.Parameters.Count == 3 &&
         m.DeclaringType != null &&                    // <=
         m.DeclaringType.Name != ContractClassName));
}

Mono

V3027 The variable 'curr' was utilized in the logical expression before it was verified against null in the same logical expression. Mono.Parallel-net_4_x ConcurrentSkipList.cs 306


Node leftSentinel;
....
IEnumerator<T> GetInternalEnumerator ()
{
  Node curr = leftSentinel;
  while ((curr = curr.Nexts [0]) != rightSentinel &&
         curr != null) {
    ....
  }
}

PowerShell

V3027 The variable 'remoteFileStreams' was utilized in the logical expression before it was verified against null in the same logical expression. System.Management.Automation FileSystemProvider.cs 4126


private void CopyFileFromRemoteSession(....)
{
  ....
  ArrayList remoteFileStreams =
    GetRemoteSourceAlternateStreams(ps, sourceFileFullName);
  if ((remoteFileStreams.Count > 0) &&
      (remoteFileStreams != null))
  ....
}

Orchard CMS

V3027 The variable 'x.Container' was utilized in the logical expression before it was verified against null in the same logical expression. ContainerService.cs 130


public IContentQuery<....> GetContentItemsQuery(....) {
  options = options ?? VersionOptions.Published;
  var query = _contentManager
              .Query<CommonPart, CommonPartRecord>(options);

  query = ids == null ?
        query.Where(x => x.Container.Id == containerId) :
        query.Where(x =>
                     (x.Container.Id == containerId ||
                      x.Container == null) &&
                    ids.Contains(x.Id));

  return query.Join<ContainablePartRecord>();
}

Umbraco

V3027 The variable 'rootDoc' was utilized in the logical expression before it was verified against null in the same logical expression. publishRootDocument.cs 34


public bool Execute(....)
{
  ....
  if (rootDoc.Text.Trim() == documentName.Trim() &&
      rootDoc != null && rootDoc.ContentType != null)
  ....
}


Do you make errors in the code?

Check your code
with PVS-Studio

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

goto PVS-Studio;