Examples of errors detected by the V3095 diagnostic.

V3095. The object was used before it was verified against null. Check lines: N1, N2.


WPF samples by Microsoft

V3095 The 'htmlLiElement' object was used before it was verified against null. Check lines: 916, 936. HtmlToXamlConverter.cs 916


private static XmlElement AddOrphanListItems(....)
{
  Debug.Assert(htmlLiElement.LocalName.ToLower() == "li");
  ....
  XmlNode htmlChildNode = htmlLiElement;
  var htmlChildNodeName = htmlChildNode == null
      ? null
      : htmlChildNode.LocalName.ToLower();
  ....
}

Old NASA World Wind (C#)

V3095 The 'this.linePoints' object was used before it was verified against null. Check lines: 332, 346. PathLine.cs 332


public override void Render(DrawArgs drawArgs)
{
  ....
  if(this.linePoints.Length > 1)    // <=
  {
    ....
    if(this.linePoints != null)     // <=
    {
      ....
    }
  }
  ....
}

Also see V3022


FlashDevelop

V3095 The 'node' object was used before it was verified against null. Check lines: 364, 365. ProjectContextMenu.cs 364


private void AddFolderItems(MergableMenu menu, string path)
{
  ....
  DirectoryNode node = projectTree.SelectedNode
    as DirectoryNode;
  if (node.InsideClasspath == node)
    menu.Add(RemoveSourcePath, 2, true);
  else if (node != null && ....)
  {
    menu.Add(AddSourcePath, 2, false);
  }
  ....
}

Unity3D

V3095 The 'uv2.gameObject' object was used before it was verified against null. Check lines: 1719, 1731. UnityEngine.Networking NetworkServer.cs 1719


static public bool SpawnObjects()
{
  ....
  if (uv2.gameObject.hideFlags == HideFlags.NotEditable ||
      uv2.gameObject.hideFlags == HideFlags.HideAndDontSave)
    continue;
  ....
  if (uv2.gameObject == null)
    continue;
  ....
}

Identical errors can be found in some other places:

  • V3095 The 'm_HorizontalScrollbarRect' object was used before it was verified against null. Check lines: 214, 220. UnityEngine.UI ScrollRect.cs 214
  • V3095 The 'm_VerticalScrollbarRect' object was used before it was verified against null. Check lines: 215, 221. UnityEngine.UI ScrollRect.cs 215

MSBuild

V3095 The 'diskRoots' object was used before it was verified against null. Check lines: 2656, 2659. ToolLocationHelper.cs 2656


private static void ExtractSdkDiskRootsFromEnvironment
(List<string> diskRoots, string directoryRoots)
{
  if (!String.IsNullOrEmpty(directoryRoots))
  {
    ....
    diskRoots.AddRange(splitRoots);  // <=
  }

  if (diskRoots != null)             // <=
  ....
}

Identical errors can be found in some other places:

  • V3095 The 'propertyValue' object was used before it was verified against null. Check lines: 2760, 2799. Expander.cs 2760
  • V3095 The 'publicKeyToken' object was used before it was verified against null. Check lines: 232, 236. GenerateBindingRedirects.cs 232
  • V3095 The 'searchLocation' object was used before it was verified against null. Check lines: 170, 178. Resolver.cs 170
  • And 5 additional diagnostic messages.

GitExtensions

V3095 The 'data' object was used before it was verified against null. Check lines: 319, 376. GitCommands RevisionGraph.cs 319


void DataReceived(string data)
{
  if (data.StartsWith(CommitBegin)) // <=
  {
      ....
  }

  if (!string.IsNullOrEmpty(data))
  {
      ....
  }
}

Identical errors can be found in some other places:

  • V3095 The 'line' object was used before it was verified against null. Check lines: 1979, 1981. GitCommands GitModule.cs 1979
  • V3095 The 'head' object was used before it was verified against null. Check lines: 2414, 2422. GitCommands GitModule.cs 2414

PowerShell

V3095 The 'inputParameters' object was used before it was verified against null. Check lines: 430, 436. System.Management.Automation FormatViewGenerator_Complex.cs 430


internal ComplexViewEntry
  GenerateView(....,
               FormattingCommandLineParameters inputParameters)
{
  _complexSpecificParameters =
    (ComplexSpecificParameters)inputParameters.shapeParameters;

  int maxDepth = _complexSpecificParameters.maxDepth;
  ....
  if (inputParameters != null)
    mshParameterList = inputParameters.mshParameterList;
  ....
}

PowerShell

V3095 The 'other.Parameters' object was used before it was verified against null. Check lines: 189, 192. System.Management.Automation CommandMetadata.cs 189


public CommandMetadata(CommandMetadata other)
{
  ....
  _parameters = new Dictionary<string, ParameterMetadata>(
    other.Parameters.Count, StringComparer.OrdinalIgnoreCase);

  // deep copy
  if (other.Parameters != null)
  ....
}

Orchard CMS

V3095 The 'Delegate' object was used before it was verified against null. Check lines: 37, 40. SerializableDelegate.cs 37


void ISerializable.GetObjectData(
  SerializationInfo info,
  StreamingContext context)
{
  info.AddValue("delegateType", Delegate.GetType());
  ....
  if (.... && Delegate != null)
  {
    ....
  }
}

Identical errors can be found in some other places:

  • V3095 The 'widget' object was used before it was verified against null. Check lines: 81, 93. TagsWidgetCommands.cs 81

Umbraco

V3095 The 'dataset' object was used before it was verified against null. Check lines: 48, 49. ImageCropperBaseExtensions.cs 48


internal static ImageCropData GetCrop(....)
{
  var imageCropDatas = dataset.ToArray();
  if (dataset == null || imageCropDatas.Any() == false)
    return null;
  ....
}

Identical errors can be found in some other places:

  • V3095 The 'display.PropertyEditor' object was used before it was verified against null. Check lines: 30, 43. ContentPropertyDisplayConverter.cs 30
  • V3095 The 'typedSource' object was used before it was verified against null. Check lines: 164, 198. DynamicQueryable.cs 164
  • V3095 The 'attempt.Result' object was used before it was verified against null. Check lines: 90, 113. DynamicPublishedContent.cs 90
  • And 8 additional diagnostic messages.

SharpDevelop

V3095 The 'position' object was used before it was verified against null. Check lines: 204, 206. Task.cs 204


public void JumpToPosition()
{
  if (hasLocation && !position.IsDeleted)
    ....
  else if (position != 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;