Difference between break and continue regarding to ReSharper

Hello,

i have the following code:

if (field.Value == null && value == null)
                    continue;
 
                if (value.Equals(field.Value))
                    continue;


ReSharper notices me of a possible System.NullReferenceException on value in the second if statement. Which is of course perfectly correct here.

If i change the first continue to break:

if (field.Value == null && value == null)
                    break;
 
                if (value.Equals(field.Value))
                    continue;



ReSharper stops noticing me about that possible System.NullReferenceException on value in the second if statement.
But in my understanding of continue and break in loops it does not matter if i break or continue. In both cases the second if statement will be executed if only value is null and therefore ReSharper should warn me in both cases about that possible System.NullReferenceException on value in the second if statement.

Am i right or do i miss something?

I am using Visual Studio 2012 and ReSharper 9.0

sebingel

3 comments
Comment actions Permalink

The difference between "break" and "continue" is that "break" exits the loop and "continue" continues the loop with the next iteration. So R#'s behavior is correct.

Regards
Klaus

0
Comment actions Permalink

R#'s behaviour is NOT correct in this case. If value == null, but field.Value != null, the break will not be reached, and the code will still try to evaluate value.Equals(field.Value), giving you a NullReferenceException.

I can reproduce the bug in 9.0 Update 1 (Build 9.0.20141219.130142).

0
Comment actions Permalink

Thank you very much. With your confirmation of this behavior i will report a bug on this.

0

Please sign in to leave a comment.