-
Notifications
You must be signed in to change notification settings - Fork 226
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
31a361a
commit 922d983
Showing
11 changed files
with
196 additions
and
135 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
analyzers/its/expected/Automapper/AutoMapper--net461-S112.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"issues": [ | ||
{ | ||
"id": "S112", | ||
"message": "'System.NullReferenceException' should not be thrown by user code.", | ||
"location": { | ||
"uri": "https://github.com/SonarSource/sonar-dotnet/blob/master/analyzers/its/sources/AutoMapper/src/AutoMapper/Mapper.cs#L151", | ||
"region": { | ||
"startLine": 151, | ||
"startColumn": 117, | ||
"endLine": 151, | ||
"endColumn": 164 | ||
} | ||
} | ||
} | ||
] | ||
} |
17 changes: 17 additions & 0 deletions
17
analyzers/its/expected/Automapper/AutoMapper--netstandard2.0-S112.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"issues": [ | ||
{ | ||
"id": "S112", | ||
"message": "'System.NullReferenceException' should not be thrown by user code.", | ||
"location": { | ||
"uri": "https://github.com/SonarSource/sonar-dotnet/blob/master/analyzers/its/sources/AutoMapper/src/AutoMapper/Mapper.cs#L151", | ||
"region": { | ||
"startLine": 151, | ||
"startColumn": 117, | ||
"endLine": 151, | ||
"endColumn": 164 | ||
} | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
analyzers/its/expected/akka.net/Akka.Benchmarks--netcoreapp3.1-S112.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"issues": [ | ||
{ | ||
"id": "S112", | ||
"message": "'System.Exception' should not be thrown by user code.", | ||
"location": { | ||
"uri": "https://github.com/SonarSource/sonar-dotnet/blob/master/analyzers/its/sources/akka.net/src/benchmark/Akka.Benchmarks/IO/TcpOperationsBenchmarks.cs#L149", | ||
"region": { | ||
"startLine": 149, | ||
"startColumn": 55, | ||
"endLine": 149, | ||
"endColumn": 89 | ||
} | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
analyzers/tests/SonarAnalyzer.UnitTest/TestCases/ThrowReservedExceptions.CSharp8.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System; | ||
|
||
public class Sample | ||
{ | ||
public void NullCoalesce(object arg) | ||
{ | ||
_ = arg ?? throw new Exception(); // Noncompliant | ||
// ^^^^^^^^^^^^^^^ | ||
|
||
_ = arg switch | ||
{ | ||
string s => s, | ||
_ => throw new Exception() // Noncompliant | ||
// ^^^^^^^^^^^^^^^ | ||
}; | ||
} | ||
} |
64 changes: 33 additions & 31 deletions
64
analyzers/tests/SonarAnalyzer.UnitTest/TestCases/ThrowReservedExceptions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,49 @@ | ||
using System; | ||
|
||
namespace SonarAnalyzer.UnitTest.TestCases | ||
public class ThrowReservedExceptions | ||
{ | ||
public class ThrowReservedExceptions | ||
public void Method1() | ||
{ | ||
public void Method1() | ||
{ | ||
throw new Exception(); // Noncompliant {{'System.Exception' should not be thrown by user code.}} | ||
// ^^^^^^^^^^^^^^^ | ||
|
||
throw new ApplicationException(); // Noncompliant {{'System.ApplicationException' should not be thrown by user code.}} | ||
// ^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
throw new Exception(); // Noncompliant {{'System.Exception' should not be thrown by user code.}} | ||
// ^^^^^^^^^^^^^^^ | ||
|
||
throw new SystemException(); // Noncompliant {{'System.SystemException' should not be thrown by user code.}} | ||
// ^^^^^^^^^^^^^^^^^^^^^ | ||
throw new ApplicationException(); // Noncompliant {{'System.ApplicationException' should not be thrown by user code.}} | ||
// ^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
throw new ExecutionEngineException(); // Noncompliant {{'System.ExecutionEngineException' should not be thrown by user code.}} | ||
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
throw new SystemException(); // Noncompliant {{'System.SystemException' should not be thrown by user code.}} | ||
// ^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
throw new IndexOutOfRangeException(); // Noncompliant {{'System.IndexOutOfRangeException' should not be thrown by user code.}} | ||
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
throw new ExecutionEngineException(); // Noncompliant {{'System.ExecutionEngineException' should not be thrown by user code.}} | ||
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
throw new NullReferenceException(); // Noncompliant {{'System.NullReferenceException' should not be thrown by user code.}} | ||
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
throw new IndexOutOfRangeException(); // Noncompliant {{'System.IndexOutOfRangeException' should not be thrown by user code.}} | ||
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
throw new OutOfMemoryException(); // Noncompliant {{'System.OutOfMemoryException' should not be thrown by user code.}} | ||
// ^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
throw new NullReferenceException(); // Noncompliant {{'System.NullReferenceException' should not be thrown by user code.}} | ||
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
var e = new OutOfMemoryException(); // Compliant | ||
throw new OutOfMemoryException(); // Noncompliant {{'System.OutOfMemoryException' should not be thrown by user code.}} | ||
// ^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
throw new ArgumentNullException(); // Compliant | ||
var e = new OutOfMemoryException(); // Compliant | ||
throw new ArgumentNullException(); // Compliant | ||
|
||
OutOfMemoryException e1 = (OutOfMemoryException)new ArgumentException(); // Error [CS0030] - cannot cast | ||
OutOfMemoryException e1 = (OutOfMemoryException)new ArgumentException(); // Error [CS0030] - cannot cast | ||
|
||
try | ||
{ | ||
var a = new int[0]; | ||
Console.WriteLine(a[1]); // Throw exception | ||
} | ||
catch (IndexOutOfRangeException) | ||
{ | ||
throw; // Compliant | ||
} | ||
try | ||
{ | ||
var a = new int[0]; | ||
Console.WriteLine(a[1]); // Throw exception | ||
} | ||
catch (IndexOutOfRangeException) | ||
{ | ||
throw; // Compliant | ||
} | ||
} | ||
|
||
public void Arrow() => | ||
throw new Exception(); // Noncompliant | ||
|
||
public Action Lambda() => | ||
() => throw new Exception(); // Noncompliant | ||
} |
58 changes: 27 additions & 31 deletions
58
analyzers/tests/SonarAnalyzer.UnitTest/TestCases/ThrowReservedExceptions.vb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,28 @@ | ||
Imports System | ||
Public Class ThrowReservedExceptions | ||
Public Sub Method1() | ||
Throw New Exception() ' Noncompliant {{'System.Exception' should not be thrown by user code.}} | ||
' ^^^^^^^^^^^^^^^ | ||
Throw New ApplicationException() ' Noncompliant {{'System.ApplicationException' should not be thrown by user code.}} | ||
' ^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
Throw New SystemException() ' Noncompliant {{'System.SystemException' should not be thrown by user code.}} | ||
' ^^^^^^^^^^^^^^^^^^^^^ | ||
Throw New ExecutionEngineException() ' Noncompliant {{'System.ExecutionEngineException' should not be thrown by user code.}} | ||
' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
Throw New IndexOutOfRangeException() ' Noncompliant {{'System.IndexOutOfRangeException' should not be thrown by user code.}} | ||
' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
Throw New NullReferenceException() ' Noncompliant {{'System.NullReferenceException' should not be thrown by user code.}} | ||
' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
Throw New OutOfMemoryException() ' Noncompliant {{'System.OutOfMemoryException' should not be thrown by user code.}} | ||
' ^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
Dim e = New OutOfMemoryException() ' Compliant | ||
Throw New ArgumentNullException() ' Compliant | ||
|
||
Namespace SonarAnalyzer.UnitTest.TestCases | ||
Public Class ThrowReservedExceptions | ||
Public Sub Method1() | ||
Throw New Exception() ' Noncompliant {{'System.Exception' should not be thrown by user code.}} | ||
' ^^^^^^^^^^^^^^^ | ||
Throw New ApplicationException() ' Noncompliant {{'System.ApplicationException' should not be thrown by user code.}} | ||
' ^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
Throw New SystemException() ' Noncompliant {{'System.SystemException' should not be thrown by user code.}} | ||
' ^^^^^^^^^^^^^^^^^^^^^ | ||
Throw New ExecutionEngineException() ' Noncompliant {{'System.ExecutionEngineException' should not be thrown by user code.}} | ||
' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
Throw New IndexOutOfRangeException() ' Noncompliant {{'System.IndexOutOfRangeException' should not be thrown by user code.}} | ||
' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
Throw New NullReferenceException() ' Noncompliant {{'System.NullReferenceException' should not be thrown by user code.}} | ||
' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
Throw New OutOfMemoryException() ' Noncompliant {{'System.OutOfMemoryException' should not be thrown by user code.}} | ||
' ^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
Dim e = New OutOfMemoryException() ' Compliant | ||
Throw New ArgumentNullException() ' Compliant | ||
|
||
Try | ||
Dim a = New Integer(-1) {} | ||
' Throw exception | ||
Console.WriteLine(a(1)) | ||
Catch generatedExceptionName As IndexOutOfRangeException ' Compliant | ||
Throw | ||
End Try | ||
End Sub | ||
End Class | ||
End Namespace | ||
Try | ||
Dim a = New Integer(-1) {} | ||
' Throw exception | ||
Console.WriteLine(a(1)) | ||
Catch generatedExceptionName As IndexOutOfRangeException ' Compliant | ||
Throw | ||
End Try | ||
End Sub | ||
End Class |