/
NullPointerDereference.CSharp11.cs
47 lines (44 loc) · 1.45 KB
/
NullPointerDereference.CSharp11.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using System;
namespace SonarAnalyzer.UnitTest.TestCases.SymbolicExecution.Sonar
{
public class NullPointerDereference
{
[Obsolete(nameof(argument.Trim))] // Compliant
public void ExtendedScopeNameOfInAttribute(string argument)
{
string nullArgument = null;
nullArgument.Trim(); // Noncompliant
}
public void ListPattern(object[] objects)
{
if (objects is [null, null, null])
{
objects[1].GetHashCode(); // FN
}
}
}
// https://github.com/SonarSource/sonar-dotnet/issues/6766
public class Repo_6766
{
public void SwitchCasePattern(object o, object[] array)
{
switch (o)
{
case (1 or 2): // Parenthesized
case 3 or 4: // Binary
case > 5: // Relational
case char: // Type
case Exception { Message.Length: 1 }: // Recursive
case (int _, int _): // Recursive
case not "": // Unary
break;
}
switch (array)
{
case []: // list pattern
case [1, .., 2]: // list pattern with slice
break;
}
}
}
}