-
Notifications
You must be signed in to change notification settings - Fork 230
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
S1854: Add FP repro for #9466, #9467, #9468 #9469
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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 | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -1030,7 +1030,7 @@ public static class ReproIssues | |||||||||
// https://github.com/SonarSource/sonar-dotnet/issues/2760 | ||||||||||
public static long WithNonIgnored_Declaration(string path) | ||||||||||
{ | ||||||||||
long length = 42; // Muted FP, FileInfo can throw and function can return this value | ||||||||||
long length = 42; // Compliant, FileInfo can throw and function can return this value | ||||||||||
try | ||||||||||
{ | ||||||||||
length = new System.IO.FileInfo(path).Length; | ||||||||||
|
@@ -1045,7 +1045,7 @@ public static long WithNonIgnored_Declaration(string path) | |||||||||
public static long WithNonIgnored_Assignment(string path) | ||||||||||
{ | ||||||||||
long length; | ||||||||||
length = 42; // Muted FP, FileInfo can throw and function can return this value | ||||||||||
length = 42; // Compliant, FileInfo can throw and function can return this value | ||||||||||
try | ||||||||||
{ | ||||||||||
length = new System.IO.FileInfo(path).Length; | ||||||||||
|
@@ -1402,7 +1402,7 @@ public class Repro_4948 | |||||||||
|
||||||||||
public void UsedInFinally() | ||||||||||
{ | ||||||||||
int value = 42; // Compliant, Muted | ||||||||||
int value = 42; // Compliant | ||||||||||
try | ||||||||||
{ | ||||||||||
SomethingThatCanThrow(); | ||||||||||
|
@@ -1439,7 +1439,7 @@ public void UsedInFinally_NestedInLambda() | |||||||||
|
||||||||||
public void UsedInFinally_Throw() | ||||||||||
{ | ||||||||||
var value = 42; // Compliant | ||||||||||
var value = 42; // Compliant | ||||||||||
try | ||||||||||
{ | ||||||||||
throw new Exception(); | ||||||||||
|
@@ -1452,7 +1452,7 @@ public void UsedInFinally_Throw() | |||||||||
|
||||||||||
public void UsedInFinally_Throw_FilteredCatch() | ||||||||||
{ | ||||||||||
var value = 42; // Compliant | ||||||||||
var value = 42; // Compliant | ||||||||||
try | ||||||||||
{ | ||||||||||
throw new Exception(); | ||||||||||
|
@@ -1470,7 +1470,7 @@ public void UsedInFinally_Throw_FilteredCatch() | |||||||||
Use(value); | ||||||||||
} | ||||||||||
} | ||||||||||
|
||||||||||
public void UsedInFinally_Throw_CatchAll() | ||||||||||
{ | ||||||||||
var value = 42; // Noncompliant | ||||||||||
|
@@ -1516,3 +1516,114 @@ public void TryReturns_Loop() | |||||||||
private void SomethingThatCanThrow() { } | ||||||||||
} | ||||||||||
} | ||||||||||
|
||||||||||
public class PeachValidation | ||||||||||
{ | ||||||||||
// https://github.com/SonarSource/sonar-dotnet/issues/9466 | ||||||||||
public int ReadInFinallyAfterCatch() | ||||||||||
{ | ||||||||||
var value = 0; | ||||||||||
try | ||||||||||
{ | ||||||||||
CanThrow(); | ||||||||||
value = 42; | ||||||||||
} | ||||||||||
catch | ||||||||||
{ | ||||||||||
value = 1; // Noncompliant FP, used in finally after the throw | ||||||||||
throw; | ||||||||||
} | ||||||||||
finally | ||||||||||
{ | ||||||||||
Log(value); | ||||||||||
} | ||||||||||
return value; | ||||||||||
} | ||||||||||
|
||||||||||
// https://github.com/SonarSource/sonar-dotnet/issues/9467 | ||||||||||
public int ReadAfterCatchAll_WithType(bool condition) | ||||||||||
{ | ||||||||||
var value = 100; // Noncompliant FP, used after catch all | ||||||||||
try | ||||||||||
{ | ||||||||||
CanThrow(); | ||||||||||
if (condition) | ||||||||||
{ | ||||||||||
CanThrow(); | ||||||||||
} | ||||||||||
value = 200; | ||||||||||
} | ||||||||||
catch (Exception exc) | ||||||||||
{ | ||||||||||
} | ||||||||||
return value; | ||||||||||
} | ||||||||||
|
||||||||||
// https://github.com/SonarSource/sonar-dotnet/issues/9467 | ||||||||||
public int ReadAfterCatchAll_NoType(bool condition) | ||||||||||
{ | ||||||||||
var value = 100; // Noncompliant FP, used after catch all | ||||||||||
try | ||||||||||
{ | ||||||||||
CanThrow(); | ||||||||||
if (condition) | ||||||||||
{ | ||||||||||
CanThrow(); | ||||||||||
} | ||||||||||
value = 200; | ||||||||||
} | ||||||||||
catch (Exception exc) | ||||||||||
{ | ||||||||||
} | ||||||||||
Comment on lines
+1575
to
+1577
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
return value; | ||||||||||
} | ||||||||||
|
||||||||||
// https://github.com/SonarSource/sonar-dotnet/issues/9467 | ||||||||||
public void ReadInCatch_WithBranching(bool condition) | ||||||||||
{ | ||||||||||
var value = 100; // Noncompliant FP, used in catch | ||||||||||
try | ||||||||||
{ | ||||||||||
value = CanThrow(); | ||||||||||
if (condition) | ||||||||||
{ | ||||||||||
CanThrow(); | ||||||||||
} | ||||||||||
else | ||||||||||
{ | ||||||||||
CanThrow(); | ||||||||||
} | ||||||||||
} | ||||||||||
catch | ||||||||||
{ | ||||||||||
Log(value); | ||||||||||
} | ||||||||||
} | ||||||||||
|
||||||||||
// https://github.com/SonarSource/sonar-dotnet/issues/9468 | ||||||||||
public void NestedCatchAndRethrow() | ||||||||||
{ | ||||||||||
var value = 100; | ||||||||||
try | ||||||||||
{ | ||||||||||
try | ||||||||||
{ | ||||||||||
CanThrow(); | ||||||||||
Comment on lines
+1607
to
+1611
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||||
} | ||||||||||
catch | ||||||||||
{ | ||||||||||
value = 200; // Noncompliant FP | ||||||||||
throw; | ||||||||||
} | ||||||||||
} | ||||||||||
catch | ||||||||||
{ | ||||||||||
Log(value); | ||||||||||
} | ||||||||||
} | ||||||||||
|
||||||||||
private int CanThrow() => | ||||||||||
throw new Exception(); | ||||||||||
|
||||||||||
private void Log(int value) { } | ||||||||||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Slightly more ecological.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While I'd normally do that, in this case, the catch has significant impact on the flow so I wanted to waste a bit of space on it.