question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Thank you very much for sharing the analyzer. I’m in process of trying this out with Rubberduck-VBA. This project involves quite a lot of manual management due to deep COM interop and a large part of architecture relies on IDisposable interface to explicitly control the lifetime of wrapped COM objects.

I’ve found few false positives. I do not know if those are something we can fix or enhance but I thought I’d at least point them out.

With IDISP001 rule we are flagged here:

var component = _state.ProjectsProvider.Component(target.QualifiedName.QualifiedModuleName);

The component here is a IDisposable object which we obtain via the _projectsProvider.Component. The intention with the ProjectsRepository is that the class is responsible for the lifetime of its objects, so thus we shouldn’t dispose anything we get out of the ProjectsRepository.

We have a similar situation here:

var subclass = Subclasses.Subclass(hwnd);

As above, Subclass returns a IDisposable object from a cached collection.

With IDSIP007 rule we also get flagged here:

using (var module = component.CodeModule)
{
  ...
}

In this case, CodeModule is similarly a IDisposable object. However, the CodeModule property reads:

public ICodeModule CodeModule => new CodeModule(IsWrappingNullReference ? null : Target.CodeModule);

Thus, using is actually appropriate in this case since we get a new object and thus are responsible for disposing it.

With IDISP003, we have a false positive for this code:

        void ComTypes.ITypeInfo.GetRefTypeInfo(int hRef, out ComTypes.ITypeInfo ppTI)
            => ppTI = GetSafeRefTypeInfo(hRef);

This flags the ppTI as needing to be disposed. What I don’t get, though is that the variable has type of ITypeInfo, which does not implement IDisposable. If I try to apply the quickfix, I get the following code:

        void ComTypes.ITypeInfo.GetRefTypeInfo(int hRef, out ComTypes.ITypeInfo ppTI)
        {
            (ppTI as IDisposable)?.Dispose();
            return ppTI = GetSafeRefTypeInfo(hRef);
        }

Which does not look at all appropriate to me.

Another example is here for this section of code:

                            IHostApplication result;
                            if (hostAppControl.IsWrappingNullReference)
                            {
                                result = null;
                            }
                            else
                            {
                                switch (hostAppControl.Caption)
                                {
                                    case "Microsoft Excel":
                                        result = new ExcelApp();
                                        break;
                                    ...<several other cases>....
                                    default:
                                        result = null;
                                        break;
                                }
                            }

                            _host = result;
                            return result;

For each case, the result is flagged in spite of the fact that it’s a local variable and thus cannot be been previously assigned.

I have not gone though all other issues and will update as I proceed.

I know we can add suppress message but I want to avoid suppressing it everything. We got about 1500 warnings and we’re going to have to assess them one by one because of some false positives.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:11

github_iconTop GitHub Comments

1reaction
JohanLarssoncommented, Nov 4, 2018
using (var module = component.CodeModule)
{
}

Reason IDISP007 nags here is again heuristics, it assumes that a property does not return a created disposable that the ~caller owns. Needs annotations #126

A property returning a created reference type is not awesome design if you ask me.

0reactions
JohanLarssoncommented, Jan 13, 2019

Closing this, open new issues if I forgot things.

Read more comments on GitHub >

github_iconTop Results From Across the Web

False positives and false negatives
A false positive error, or false positive, is a result that indicates a given condition exists when it does not. For example, a...
Read more >
Practices of Science: False Positives and False Negatives
A false positive is when a scientist determines something is true when it is actually false (also called a type I error). A...
Read more >
False Positive - Glossary | CSRC
False Positive · An alert that incorrectly indicates that a vulnerability is present. · An alert that incorrectly indicates that malicious activity is...
Read more >
Classification: True vs. False and Positive vs. Negative
A false positive is an outcome where the model incorrectly predicts the positive class. And a false negative is an outcome where the...
Read more >
False-Positive Results in Rapid Antigen Tests for SARS ...
This study examines the incidence of false-positive results in a sample of rapid antigen tests used to serially screen asymptomatic workers ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found