{"action":"created","issue":{"url":"https://api.github.com/repos/DotNetAnalyzers/IDisposableAnalyzers/issues/125","repository_url":"https://api.github.com/repos/DotNetAnalyzers/IDisposableAnalyzers","labels_url":"https://api.github.com/repos/DotNetAnalyzers/IDisposableAnalyzers/issues/125/labels{/name}","comments_url":"https://api.github.com/repos/DotNetAnalyzers/IDisposableAnalyzers/issues/125/comments","events_url":"https://api.github.com/repos/DotNetAnalyzers/IDisposableAnalyzers/issues/125/events","html_url":"https://github.com/DotNetAnalyzers/IDisposableAnalyzers/issues/125","id":377121211,"node_id":"MDU6SXNzdWUzNzcxMjEyMTE=","number":125,"title":"False positives","user":{"login":"bclothier","id":2367644,"node_id":"MDQ6VXNlcjIzNjc2NDQ=","avatar_url":"https://avatars2.githubusercontent.com/u/2367644?v=4","gravatar_id":"","url":"https://api.github.com/users/bclothier","html_url":"https://github.com/bclothier","followers_url":"https://api.github.com/users/bclothier/followers","following_url":"https://api.github.com/users/bclothier/following{/other_user}","gists_url":"https://api.github.com/users/bclothier/gists{/gist_id}","starred_url":"https://api.github.com/users/bclothier/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bclothier/subscriptions","organizations_url":"https://api.github.com/users/bclothier/orgs","repos_url":"https://api.github.com/users/bclothier/repos","events_url":"https://api.github.com/users/bclothier/events{/privacy}","received_events_url":"https://api.github.com/users/bclothier/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":6,"created_at":"2018-11-04T04:55:15Z","updated_at":"2018-11-04T10:45:28Z","closed_at":null,"author_association":"NONE","body":"Thank you very much for sharing the analyzer. I'm in process of trying this out with [Rubberduck-VBA](https://github.com/rubberduck-vba/Rubberduck). 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.\r\n\r\nI'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.\r\n\r\nWith `IDISP001` rule we are flagged here:\r\n```\r\nvar component = _state.ProjectsProvider.Component(target.QualifiedName.QualifiedModuleName);\r\n```\r\n\r\nThe `component` here is a `IDisposable` object which we obtain via the [`_projectsProvider.Component`](https://github.com/rubberduck-vba/Rubberduck/blob/23039cc5ecda48fb1b8acd4da0d982c9149dab54/Rubberduck.VBEEditor/ComManagement/ProjectsRepository.cs#L243). 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`. \r\n\r\nWe have a similar situation here:\r\n```\r\nvar subclass = Subclasses.Subclass(hwnd);\r\n```\r\n\r\nAs above, `Subclass` returns a `IDisposable` object from [a cached collection](https://github.com/rubberduck-vba/Rubberduck/blob/70f513df1c65138fe12530943b3c580afbed08af/Rubberduck.VBEEditor/WindowsApi/SubclassManager.cs#L31).\r\n\r\nWith `IDSIP007` rule we also get flagged here:\r\n```\r\nusing (var module = component.CodeModule)\r\n{\r\n  ...\r\n}\r\n```\r\n\r\nIn this case, `CodeModule` is similarly a `IDisposable` object. However, [the `CodeModule` property](https://github.com/rubberduck-vba/Rubberduck/blob/23039cc5ecda48fb1b8acd4da0d982c9149dab54/Rubberduck.VBEditor.VBA/SafeComWrappers/VB/VBComponent.cs#L22) reads:\r\n```\r\npublic ICodeModule CodeModule => new CodeModule(IsWrappingNullReference ? null : Target.CodeModule);\r\n```\r\n\r\nThus, `using` is actually appropriate in this case since we get a new object and thus are responsible for disposing it.\r\n\r\nWith `IDISP003`, we have a false positive for [this code](https://github.com/rubberduck-vba/Rubberduck/blob/next/Rubberduck.VBEEditor/ComManagement/TypeLibs/TypeInfos.cs#L802):\r\n```\r\n        void ComTypes.ITypeInfo.GetRefTypeInfo(int hRef, out ComTypes.ITypeInfo ppTI)\r\n            => ppTI = GetSafeRefTypeInfo(hRef);\r\n```\r\n\r\nThis 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:\r\n```\r\n        void ComTypes.ITypeInfo.GetRefTypeInfo(int hRef, out ComTypes.ITypeInfo ppTI)\r\n        {\r\n            (ppTI as IDisposable)?.Dispose();\r\n            return ppTI = GetSafeRefTypeInfo(hRef);\r\n        }\r\n```\r\n\r\nWhich does not look at all appropriate to me. \r\n\r\n\r\nAnother example is here for [this section of code](https://github.com/rubberduck-vba/Rubberduck/blob/next/Rubberduck.VBEditor.VBA/SafeComWrappers/VB/VBE.cs#L213):\r\n```\r\n                            IHostApplication result;\r\n                            if (hostAppControl.IsWrappingNullReference)\r\n                            {\r\n                                result = null;\r\n                            }\r\n                            else\r\n                            {\r\n                                switch (hostAppControl.Caption)\r\n                                {\r\n                                    case \"Microsoft Excel\":\r\n                                        result = new ExcelApp();\r\n                                        break;\r\n                                    ...<several other cases>....\r\n                                    default:\r\n                                        result = null;\r\n                                        break;\r\n                                }\r\n                            }\r\n\r\n                            _host = result;\r\n                            return result;\r\n```\r\n\r\nFor each case, the `result` is flagged in spite of the fact that it's a local variable and thus cannot be been previously assigned. \r\n\r\nI have not gone though all other issues and will update as I proceed. \r\n\r\nI 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."},"comment":{"url":"https://api.github.com/repos/DotNetAnalyzers/IDisposableAnalyzers/issues/comments/435659139","html_url":"https://github.com/DotNetAnalyzers/IDisposableAnalyzers/issues/125#issuecomment-435659139","issue_url":"https://api.github.com/repos/DotNetAnalyzers/IDisposableAnalyzers/issues/125","id":435659139,"node_id":"MDEyOklzc3VlQ29tbWVudDQzNTY1OTEzOQ==","user":{"login":"JohanLarsson","id":1640096,"node_id":"MDQ6VXNlcjE2NDAwOTY=","avatar_url":"https://avatars0.githubusercontent.com/u/1640096?v=4","gravatar_id":"","url":"https://api.github.com/users/JohanLarsson","html_url":"https://github.com/JohanLarsson","followers_url":"https://api.github.com/users/JohanLarsson/followers","following_url":"https://api.github.com/users/JohanLarsson/following{/other_user}","gists_url":"https://api.github.com/users/JohanLarsson/gists{/gist_id}","starred_url":"https://api.github.com/users/JohanLarsson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JohanLarsson/subscriptions","organizations_url":"https://api.github.com/users/JohanLarsson/orgs","repos_url":"https://api.github.com/users/JohanLarsson/repos","events_url":"https://api.github.com/users/JohanLarsson/events{/privacy}","received_events_url":"https://api.github.com/users/JohanLarsson/received_events","type":"User","site_admin":false},"created_at":"2018-11-04T10:45:28Z","updated_at":"2018-11-04T10:45:28Z","author_association":"COLLABORATOR","body":"Looks like I'm dumbing analysis in the switch also."}}
{"actor":{"display_login":"JohanLarsson"}}