From c16cb57dd9d096bb2c893e3565b18de1030d82ea Mon Sep 17 00:00:00 2001 From: Zsolt Kolbay <121798625+zsolt-kolbay-sonarsource@users.noreply.github.com> Date: Tue, 18 Apr 2023 11:02:38 +0200 Subject: [PATCH] Update RSPEC (#6899) --- analyzers/rspec/cs/S3655_c#.html | 4 +- analyzers/rspec/cs/S3900_c#.html | 2 +- analyzers/rspec/vbnet/S3655_vb.net.html | 40 +++++++++---------- .../src/SonarAnalyzer.CSharp/sonarpedia.json | 2 +- .../SonarAnalyzer.VisualBasic/sonarpedia.json | 2 +- 5 files changed, 24 insertions(+), 26 deletions(-) diff --git a/analyzers/rspec/cs/S3655_c#.html b/analyzers/rspec/cs/S3655_c#.html index 41a8dfe91e3..32126c16d98 100644 --- a/analyzers/rspec/cs/S3655_c#.html +++ b/analyzers/rspec/cs/S3655_c#.html @@ -1,6 +1,6 @@
Nullable value types can hold either a value or null
. The value held in the nullable type can be accessed with the Value
-property or by casting it to the underlying type, but both operations throw an InvalidOperationException
when the value is
-null
. To avoid the exception, a nullable type should always be tested before the value is accessed.
InvalidOperationException
when the value is
+null
. A nullable type should always be tested before the value is accessed to avoid the exception.
public void Sample(bool condition) diff --git a/analyzers/rspec/cs/S3900_c#.html b/analyzers/rspec/cs/S3900_c#.html index 1de43aa95eb..2f44d83a2d7 100644 --- a/analyzers/rspec/cs/S3900_c#.html +++ b/analyzers/rspec/cs/S3900_c#.html @@ -56,7 +56,7 @@diff --git a/analyzers/rspec/vbnet/S3655_vb.net.html b/analyzers/rspec/vbnet/S3655_vb.net.html index 680be2d2e4c..4d80e6ab86f 100644 --- a/analyzers/rspec/vbnet/S3655_vb.net.html +++ b/analyzers/rspec/vbnet/S3655_vb.net.html @@ -1,31 +1,29 @@Compliant Solution
private void Xyzzy(MyOtherClass other) { - this.other = other; // Compliant: method is not publicly accessible + this.other = other.Clone(); // Compliant: method is not publicly accessible } }
Nullable value types can hold either a value or Nothing
. The value stored in the nullable type can be accessed with the
Value
property or by casting it to the underlying type. Still, both operations throw an InvalidOperationException
when the
-value is Nothing
. A nullable type should always be tested before Value
is accessed to avoid the exception.
Nothing
. A nullable type should always be tested before the value is accessed to avoid the exception.
-Dim nullable As Integer? = Nothing -Console.WriteLine(nullable.Value) --
or
--Dim nullable As Integer? = Nothing -Console.WriteLine(CType(nullable, Integer)) +Sub Sample(condition As Boolean) + Dim nullableValue As Integer? = If(condition, 42, Nothing) + Console.WriteLine(nullableValue.Value) ' Noncompliant + + Dim nullableCast As Integer? = If(condition, 42, Nothing) + Console.WriteLine(CType(nullableCast, Integer)) ' Noncompliant +End Sub
-Dim nullable As Integer? = Nothing -If nullable.HasValue Then - Console.WriteLine(nullable.Value) - Console.WriteLine(CType(nullable, Integer)) -End If --
or
--Dim nullable As Integer? = Nothing -If nullable <> Nothing Then - Console.WriteLine(nullable.Value) - Console.WriteLine(CType(nullable, Integer)) -End If +Sub Sample(condition As Boolean) + Dim nullableValue As Integer? = If(condition, 42, Nothing) + If nullableValue.HasValue Then + Console.WriteLine(nullableValue.Value) + End If + + Dim nullableCast As Integer? = If(condition, 42, Nothing) + If nullableCast.HasValue Then + Console.WriteLine(CType(nullableCast, Integer)) + End If +End Sub