You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
S1751: Remove this 'return' statement or make it unconditional doesn't take into account exceptions
Repro steps
The function generates this warning
protected virtual bool MoveWithRetry(string sourceFileName, string destFileName)
{
ResetRetryTimeout();
while (true) {
try {
HBAS.IO.File.MoveReplace(sourceFileName, destFileName);
return true;
} catch (System.Exception e) {
int ecode = System.Runtime.InteropServices.Marshal.GetHRForException(e);
if (ecode == unchecked((int)0x80070005) ||
ecode == unchecked((int)0x80070020)) {
// The reason was ERROR_ACCESS_DENIED or ERROR_SHARING_VIOLATION
if (!WaitRetryTimeout()) throw;
} else if (ecode == unchecked((int)0x80070002)) {
// The reason was ERROR_FILE_NOT_FOUND
return false;
} else {
throw;
}
}
};
}
If the method HBAS.IO.File.MoveReplace raises an exception, it will go in the catch. There is a section there where it will exit the catch and go back to the beginning of the while loop, particularly if it's one of two types (0x80070005 or 0x80070020) and there's no timeout which checks against a Stopwatch object.
Expected behavior
This false positive shouldn't occur
Actual behavior
See expected behaviour
Known workarounds
None
Related information
SonarC# Version 3.3.0
Visual Studio Version 2015
The text was updated successfully, but these errors were encountered:
michalb-sonar
changed the title
S1751 false alarm when used with exceptions
Fix S1751: Rule should not raise on "retry on exception" pattern.
Jul 24, 2017
Evangelink
changed the title
Fix S1751: Rule should not raise on "retry on exception" pattern.
Fix S1751: Rule should not raise on "retry on exception" pattern
Jul 25, 2017
Description
S1751: Remove this 'return' statement or make it unconditional doesn't take into account exceptions
Repro steps
The function generates this warning
If the method HBAS.IO.File.MoveReplace raises an exception, it will go in the catch. There is a section there where it will exit the catch and go back to the beginning of the while loop, particularly if it's one of two types (0x80070005 or 0x80070020) and there's no timeout which checks against a Stopwatch object.
Expected behavior
This false positive shouldn't occur
Actual behavior
See expected behaviour
Known workarounds
None
Related information
The text was updated successfully, but these errors were encountered: