Bug Report T564802
Visible to All Users

Code Analysis - The 'If-block matches else block' diagnostic false positive

created 7 years ago

When using CodeRush for Roslyn, I noticed a false positive coming from one of the analyzers. This is to do with the if block matching the else block, below is the excerpt of code:

Visual Basic
If Value.TriggerIdentity.DataSetIdentity.DataSetIndex = 0 OrElse Value.TriggerIdentity.TriggerIndex = 0 Then Exit Sub

As you would probably agree, this is a false positive.

Show previous comments (7)

    Alex, hopefully this is a better example of what I hope would be considered a false positive:

    Visual Basic
    If PhoneNumber.Substring(2, 1) = "0" Then 'Eight Digit Local Number Return "(" & PhoneNumber.Substring(0, 3) & ") " & PhoneNumber.Substring(3, PhoneNumber.Length - 3) ElseIf PhoneNumber.Substring(2, 1) = "6" Then If PhoneNumber.Length >= 5 AndAlso PhoneNumber.Substring(3, 2) = "24" Then '07624 Return "(" & PhoneNumber.Substring(0, 5) & ") " & PhoneNumber.Substring(5, PhoneNumber.Length - 5) Else 'Eight Digit Local Number Return "(" & PhoneNumber.Substring(0, 3) & ") " & PhoneNumber.Substring(3, PhoneNumber.Length - 3) End If Else 'Eight Digit Local Number Return "(" & PhoneNumber.Substring(0, 3) & ") " & PhoneNumber.Substring(3, PhoneNumber.Length - 3) End If

    While I appreciate that there are two branches within the if statement that are the same, there is an elseif statement between them, which would in my opinion, render this warning invalid. As we are using the code in the elseif statement to determine which branch of code to execute.

    AE AE
    Alex Eg (DevExpress) 7 years ago

      Mark,
      Thank you for the code sample. Please give us some time to research the situation in detail and see if we can improve the analysis engine.

        Not a problem, always happy to help improve and provide feedback.

        Answers approved by DevExpress Support

        created 7 years ago

        We have fixed the issue described in this ticket and will include the fix in our next maintenance update. To apply this solution before the official update, request a hotfix by clicking the corresponding link for product versions you require.

        Note: Hotfixes may be unavailable for beta versions and updates that are about to be released.

          Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

          Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.