Object may be null + Empty general catch clause

I was reviewing a project earlier today and discovered an interesting method that uncovers a couple of outstanding issues in ReSharper 3.02. I created a sample method with as little code as possible to illustrate the issues. The first issue that is that the code determines if ISyncResult state is null and jump to a label if it is. This bypasses the line of code between the catch block and the label, but ReSharper highlights state.AsyncState claiming that state may be null. I suspect this is because ReSharper is ignoring the goto statement.

The second issue I noticed is that ReSharper no longer highlights empty general catch clauses if the catch clause contains a lonely little semicolon.

public void Test()
{
IAsyncResult state = null;

try
{
if(state == null)
{
goto somewhere;
}
}
catch
{
;
}

object obj = state.AsyncState;

somewhere:
;
}

Attachment not added (content type not allowed): "att1.html"

2 comments
Comment actions Permalink

"Lothan" <lothan@newsguy.com> wrote in message
news:faoaae$sq0$1@is.intellij.net...
I was reviewing a project earlier today and discovered an interesting method
that uncovers a couple of outstanding issues in ReSharper 3.02. I created a
sample method with as little code as possible to illustrate the issues. The
first issue that is that the code determines if ISyncResult state is null
and jump to a label if it is. This bypasses the line of code between the
catch block and the label, but ReSharper highlights state.AsyncState
claiming that state may be null. I suspect this is because ReSharper is
ignoring the goto statement.
-


Or, it could be failing to realize that the "if" statement can't throw an
exception. If it ever did throw an exception, that would wind up in the
catch statement, then fall through to get the NullReferenceException.
--
John

0
Comment actions Permalink

It's sloppy code in either case, and I finally refactored it into something
a bit more sensible.

"John Saunders" <john.saunders@trizetto.com> wrote in message
news:faqijj$jj3$1@is.intellij.net...

"Lothan" <lothan@newsguy.com> wrote in message
news:faoaae$sq0$1@is.intellij.net...
I was reviewing a project earlier today and discovered an interesting
method that uncovers a couple of outstanding issues in ReSharper 3.02. I
created a sample method with as little code as possible to illustrate the
issues. The first issue that is that the code determines if ISyncResult
state is null and jump to a label if it is. This bypasses the line of code
between the catch block and the label, but ReSharper highlights
state.AsyncState claiming that state may be null. I suspect this is
because ReSharper is ignoring the goto statement.
------
Or, it could be failing to realize that the "if" statement can't throw an
exception. If it ever did throw an exception, that would wind up in the
catch statement, then fall through to get the NullReferenceException.
--
John


0

Please sign in to leave a comment.