Skip to content

Commit

Permalink
Update rspec
Browse files Browse the repository at this point in the history
  • Loading branch information
costin-zaharia-sonarsource committed Oct 8, 2020
1 parent faa4ff8 commit cb893fc
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 11 deletions.
12 changes: 8 additions & 4 deletions sonaranalyzer-dotnet/rspec/cs/S3966_c#.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
<p>A proper implementation of <code>IDisposable.Dispose</code> should allow for it to be called multiple times on the same object, however this is not
guaranteed and could result in an exception being thrown.</p>
<p>It is best not to rely on this behavior and therefore make sure an object is disposed only once on all execution paths. This is particularly true
when dealing with nested <code>using</code> statements.</p>
<p>Disposing an object twice, either with the <code>using</code> keyword or by calling <code>Dispose</code> directly, in the same method is at best
confusing and at worst error-prone. The next developer might see only one of the <code>Dispose</code>/<code>using</code> and try to use an
already-disposed object.</p>
<p>In addition, even if <a href="https://docs.microsoft.com/en-us/dotnet/api/system.idisposable.dispose?view=netcore-3.1">the documentation of
<code>Disposable</code></a> explicitly states that calling the <code>Dispose</code> method multiple times should not throw an exception, some
implementation still do it. Thus it is safer to not dispose an object twice when possible.</p>
<p>This rule raises an issue when, in the same method, the <code>Dispose</code> method is explicitly called twice on the same object, or when
<code>using</code> is used with a direct call to <code>Dispose()</code>.</p>
<h2>Noncompliant Code Examples</h2>
<pre>
using (var d = new Disposable()) // Noncompliant
Expand Down
1 change: 1 addition & 0 deletions sonaranalyzer-dotnet/rspec/cs/S3966_c#.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"constantCost": "10min"
},
"tags": [
"confusing",
"pitfall"
],
"defaultSeverity": "Major",
Expand Down
1 change: 1 addition & 0 deletions sonaranalyzer-dotnet/rspec/cs/Sonar_way_profile.json
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@
"S3928",
"S3949",
"S3963",
"S3966",
"S3971",
"S3972",
"S3973",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8534,10 +8534,10 @@
<value>Major Code Smell</value>
</data>
<data name="S3966_Description" xml:space="preserve">
<value>A proper implementation of IDisposable.Dispose should allow for it to be called multiple times on the same object, however this is not guaranteed and could result in an exception being thrown.</value>
<value>Disposing an object twice, either with the using keyword or by calling Dispose directly, in the same method is at best confusing and at worst error-prone. The next developer might see only one of the Dispose/using and try to use an already-disposed object.</value>
</data>
<data name="S3966_IsActivatedByDefault" xml:space="preserve">
<value>False</value>
<value>True</value>
</data>
<data name="S3966_Remediation" xml:space="preserve">
<value>Constant/Issue</value>
Expand All @@ -8552,7 +8552,7 @@
<value>Major</value>
</data>
<data name="S3966_Tags" xml:space="preserve">
<value>pitfall</value>
<value>confusing,pitfall</value>
</data>
<data name="S3966_Title" xml:space="preserve">
<value>Objects should not be disposed more than once</value>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
<p>A proper implementation of <code>IDisposable.Dispose</code> should allow for it to be called multiple times on the same object, however this is not
guaranteed and could result in an exception being thrown.</p>
<p>It is best not to rely on this behavior and therefore make sure an object is disposed only once on all execution paths. This is particularly true
when dealing with nested <code>using</code> statements.</p>
<p>Disposing an object twice, either with the <code>using</code> keyword or by calling <code>Dispose</code> directly, in the same method is at best
confusing and at worst error-prone. The next developer might see only one of the <code>Dispose</code>/<code>using</code> and try to use an
already-disposed object.</p>
<p>In addition, even if <a href="https://docs.microsoft.com/en-us/dotnet/api/system.idisposable.dispose?view=netcore-3.1">the documentation of
<code>Disposable</code></a> explicitly states that calling the <code>Dispose</code> method multiple times should not throw an exception, some
implementation still do it. Thus it is safer to not dispose an object twice when possible.</p>
<p>This rule raises an issue when, in the same method, the <code>Dispose</code> method is explicitly called twice on the same object, or when
<code>using</code> is used with a direct call to <code>Dispose()</code>.</p>
<h2>Noncompliant Code Examples</h2>
<pre>
using (var d = new Disposable()) // Noncompliant
Expand Down

0 comments on commit cb893fc

Please sign in to comment.