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.

>
>
>
V3105. The 'a' variable was used after …
Analyzer Diagnostics
General Analysis (C++)
General Analysis (C#)
General Analysis (Java)
Diagnosis of micro-optimizations (C++)
Diagnosis of 64-bit errors (Viva64, C++)
MISRA errors
AUTOSAR errors
Additional information
Contents

V3105. The 'a' variable was used after it was assigned through null-conditional operator. NullReferenceException is possible.

June 29, 2016

This diagnostic warns you about the risk of getting 'NullReferenceException' and is triggered when a variable’s field is accessed without first testing that variable for null. The point here is that the value the variable refers to is computed using the null-conditional operator.

Consider the following example:

public int Foo (Person person)
{
  string parentName = person?.Parent.ToString();
  return parentName.Length;
}

When initializing the 'parentName' object, we assume that 'person' may be null. In that case, the 'ToString()' function will not be executed, and the 'parentName' variable will be assigned a null value. An attempt to read the 'Length' property from this variable will result in throwing 'NullReferenceException'.

This is what a correct version of the code above may look like:

public int Foo (Person person)
{
  string parentName = person?.Parent.ToString();
  return parentName?.Length ?? 0;
}

Now the function will return the string length if the 'parentName' variable does not refer to null, and 0 if it does.

This diagnostic is classified as:

You can look at examples of errors detected by the V3105 diagnostic.

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