mirror of
https://github.com/github/codeql.git
synced 2026-02-12 05:01:06 +01:00
28 lines
726 B
XML
28 lines
726 B
XML
<!DOCTYPE qhelp PUBLIC
|
|
"-//Semmle//qhelp//EN"
|
|
"qhelp.dtd">
|
|
<qhelp>
|
|
<overview>
|
|
<p>Catching <code>NullReferenceException</code> should not be used as an alternative to checks and
|
|
assertions for preventing dereferencing a null pointer.</p>
|
|
|
|
</overview>
|
|
<recommendation>
|
|
<p>Check if the variable is null before dereferencing it.</p>
|
|
|
|
</recommendation>
|
|
<example>
|
|
<p>The following example class, <code>findPerson</code> returns null if the person is not found.</p>
|
|
<sample src="CatchOfNullReferenceException.cs" />
|
|
|
|
<p>The following example has been updated to ensure that any null return values are handled
|
|
correctly.</p>
|
|
<sample src="CatchOfNullReferenceExceptionFix.cs" />
|
|
|
|
</example>
|
|
<references>
|
|
|
|
|
|
</references>
|
|
</qhelp>
|