FORWARD_NULL after unlocking null?

I have this line of code:

this.Path = pathLookUpLocation.GetValue(RegLookupKey, null).ToString(); 

When I run the static analysis tool (Coverity) in my code, I get FORWARD_NULL here, saying that I dereference null here. It’s hard for me to understand what this means and how can I fix it?

this.Path is a string, pathLookUpLocation is a RegistryKey, RegLookupKey is a string.

+6
source share
1 answer

I believe that pathLookUpLocation is of type RegistryKey .

The reason for this message is that your code will throw a NullReferenceException if the value with the key specified by RegLookupKey not found. This happens because you pass null as the second parameter to GetValue . The second parameter is the default value, which is returned if the key is not found.

Correct it by changing it to string.Empty :

 this.Path = pathLookUpLocation.GetValue(RegLookupKey, string.Empty).ToString(); 
+4
source

Source: https://habr.com/ru/post/911865/


All Articles