Closed NETSphereSoft closed 1 week ago
Hi @NETSphereSoft!
Just a clarification regarding the reproducer you provided, both versions are raising the issue on my side:
public class TestDisposablee : IDisposable // Noncompliant S3881
{
~TestDisposablee()
{
Dispose(false); // Also with this.Dispose(false);
}
public void Dispose()
{
Dispose(true); // Also with this.Dispose(true);
GC.SuppressFinalize(this);
}
private void Dispose(Boolean disposing)
{
// Dispose activities
}
}
It doesn't seem related to the this
keyword. Can you please provide a compliant example that becomes noncompliant when adding this
keyword to the invocation?
As pointed out by Cristian, the problem is not the this
. The Disposable pattern is not implemented correctly. The Dispose(bool disposing)
method needs to be protected virtual
:
public class TestDisposable :
IDisposable
{
~TestDisposable()
{
this.Dispose(false);
}
public void Dispose()
{
this.Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(Boolean disposing)
{
// Dispose activities
}
}
Description
Correct implementation of
Dispose
pattern with referencethis.
will not detected.Repro steps
IDisposable
implementation and usethis.
together with the method calls.Expected behavior
Scanner should take care about referencing with
this.
.Actual behavior
Dispose pattern reported false positive.
Known workarounds
pragma
todisable
the reportingthis.
Related information