Object is null on at least one execution path

false-positive

(Boiethios) #1
  • Version: 6.7.6.38781, scaner: 7.10 (build 7896)

  • Message: 'ex' is null on at least one execution path.

  • Reproduce:

    void Foo(Exception ex)
    {
        switch (ex)
        {
            // Particular case:
            case ArgumentException e:
                // --snip--
                break;
    
            // General case:
            case Exception e:
                // --snip--
                break;
    
            // If exception is null, nothing to do:
            default:
                return;
        }
    
        // 'ex' cannot be null, but SonarQube writes that 'ex' is null on at least one execution path.
        Console.WriteLine(ex.Message);
    }
    

(Valeri Hristov) #2

Hi @Boiethios,

This is indeed a problem in the rule, I created a ticket about it:

Unfortunately as with everything related to symbolic execution, I cannot give a concrete estimate when this could be fixed.

Kind regards,
Valeri