SonarQube C# Code Analysis provides on-the-fly feedback to developers on any new bug or quality issue injected into C# code. This package is based on and benefits from the .NET Compiler Platform ("Roslyn") and the related code analysis API to provide a fully-integrated user experience in Visual Studio 2015.
Bugfix for null dereferencing. Issue found by SonarQube C# Code Analy…
&& is a short-circuit and, so if x && y and x is false then y isn't evaluated, no? https://msdn.microsoft.com/en-us/library/2a723cdk.aspx
@shanselman, I believe the difference between the PR and what is currently in source is that yes you will short-circuit with &&.
So the logic in the if statement will never execute for when the pingbackService is not null but also empty (length of 0). I believe that is what @tvsonar is attempting to fix here.
Side note, got here from your blog. Good stuff.
@shanselman you are right that && short-circuits if the first part is false. But:
The original condition was pingbackService == null && pingbackService.Length == 0. Consider the case when pingbackService is null. In this case we get to this condition: true && null.Length == 0. The first part is true, so the second part will be evaluated. And it will throw a NullReferenceException.
pingbackService == null && pingbackService.Length == 0
true && null.Length == 0
@tvsonar Ah, I stand corrected, then it should really be != null, not || yes?
@shanselman, No I don't believe so.
The code block has a comment right before the code:
// if we don't get the header
// try and autodetect the auto pingback info
Then it tries to set pingbackService in the logic inside the if statement.
The || is correct because it first checks for null. If it isn't, it then checks if the length is zero.
If either condition is true, it will then use the regex split logic to set the pingbackService variable.