Our website uses cookies to enhance your browsing experience.
Accept
to the top
close form

Fill out the form in 2 simple steps below:

Your contact information:

Step 1
Congratulations! This is your promo code!

Desired license type:

Step 2
Team license
Enterprise license
** By clicking this button you agree to our Privacy Policy statement
close form
Request our prices
New License
License Renewal
--Select currency--
USD
EUR
* By clicking this button you agree to our Privacy Policy statement

close form
Free PVS‑Studio license for Microsoft MVP specialists
* By clicking this button you agree to our Privacy Policy statement

close form
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

close form
I am interested to try it on the platforms:
* By clicking this button you agree to our Privacy Policy statement

close form
check circle
Message submitted.

Your message has been sent. We will email you at


If you do not see the email in your inbox, please check if it is filtered to one of the following folders:

  • Promotion
  • Updates
  • Spam

>
>
>
Examples of errors detected by the V302…

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

PascalABC.NET

V3027 [CWE-476] The variable 'fn.return_value_type' was utilized in the logical expression before it was verified against null in the same logical expression. NetHelper.cs 1109


private static function_node get_conversion(....)
{
  ....
  function_node fn = si.sym_info as function_node;
  if (.... || fn.return_value_type.original_generic == to || ....
      && fn.return_value_type != null && ....)
  {
    return fn;
  }
  ....
}

Cloudscribe

V3027 The variable 'model' was utilized in the logical expression before it was verified against null in the same logical expression. ConsentController.cs 87


public async Task<IActionResult> Index(ConsentInputModel model)
{
  // user clicked 'no' - send back the standard
  // 'access_denied' response
  if (model.Button == "no")
  {
    response = ConsentResponse.Denied;
  }
  // user clicked 'yes' - validate the data
  else if (model.Button == "yes" && model != null)
  {
    ....
  }
  ....
}

Barotrauma

V3027 The variable 'spawnPosition' was utilized in the logical expression before it was verified against null in the same logical expression. LevelObjectManager.cs 274


private void PlaceObject(LevelObjectPrefab prefab,
                         SpawnPosition spawnPosition,
                         Level level, Level.Cave parentCave = null)
{
  float rotation = 0.0f;
  if (   prefab.AlignWithSurface
      && spawnPosition.Normal.LengthSquared() > 0.001f          // <=
      && spawnPosition != null)                                 // <=
  {
    rotation = MathUtils.VectorToAngle(new Vector2(spawnPosition.Normal.Y,
                                                   spawnPosition.Normal.X));
  }
  ....
}