From df06e27a65fa88048d9fce63a4d594f523bea8d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christophe=20Z=C3=BCrn?= <36889251+christophe-zurn-sonarsource@users.noreply.github.com> Date: Thu, 7 Nov 2019 10:43:11 +0100 Subject: [PATCH] Add S3900 FP repro for #2639 --- ...icMethodArgumentsShouldBeCheckedForNull.cs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/sonaranalyzer-dotnet/tests/SonarAnalyzer.UnitTest/TestCases/PublicMethodArgumentsShouldBeCheckedForNull.cs b/sonaranalyzer-dotnet/tests/SonarAnalyzer.UnitTest/TestCases/PublicMethodArgumentsShouldBeCheckedForNull.cs index aaa7f5eae8d..dd77c5579d5 100644 --- a/sonaranalyzer-dotnet/tests/SonarAnalyzer.UnitTest/TestCases/PublicMethodArgumentsShouldBeCheckedForNull.cs +++ b/sonaranalyzer-dotnet/tests/SonarAnalyzer.UnitTest/TestCases/PublicMethodArgumentsShouldBeCheckedForNull.cs @@ -111,9 +111,17 @@ public void Compliant1(object o) } } + [AttributeUsage(AttributeTargets.Parameter)] + public sealed class ValidatedNotNullAttribute : Attribute { } + + public static class GuardExtensionClass + { + public static void GuardExtension([ValidatedNotNull]this string value) { } + } + public class GuardedTests { - public void Guarded(string s1, string s2, string s3) + public void Guarded(string s1, string s2, string s3, string s4, string s5) { Guard1(s1); s1.ToUpper(); @@ -123,6 +131,12 @@ public void Guarded(string s1, string s2, string s3) Guard3("s3", s3); s3.ToUpper(); + + Guard4(s4); + s4.ToUpper(); + + s5.GuardExtension(); + s5.ToUpper(); // Noncompliant - FP for extensions having the [ValidatedNotNull] attribute } public void Guard1([ValidatedNotNull]T value) where T : class { } @@ -131,8 +145,7 @@ public void Guard2([ValidatedNotNull]T value, string name) where T : class { public void Guard3(string name, [ValidatedNotNull]T value) where T : class { } - [AttributeUsage(AttributeTargets.Parameter)] - public sealed class ValidatedNotNullAttribute : Attribute { } + public static void Guard4([ValidatedNotNull]T value) where T : class { } } public class ReproIssue2476