Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » Strange null-pointer warning after switch statement...
Strange null-pointer warning after switch statement... [message #556001] Mon, 30 August 2010 13:55 Go to next message
Michael Moser is currently offline Michael MoserFriend
Messages: 914
Registered: July 2009
Senior Member
I am getting an odd (IMHO false) compiler warning re. possible
dereferentiation of null pointers:

I have a switch statemement where each case handles one possible value
of an enumeration type and assigns a value (using "= new
<Constructor>(...)." ) to some variable defined right before the
switch statement. Following the switch statement there is some common
code that operates on that variable assigned above.

For some reason I am getting a null-pointer warning on the use of that
variable although IMHO there is no possible path through that switch
without assigning a value to the variable. I even added a
default-clause to the switch to cover all non-matching cases and
throwing an exception (although I claim that this fragment is
impossible to reach).

Still, the compiler issues a null-pointer warning. Why?
Any idea?

Michael
Re: Strange null-pointer warning after switch statement... [message #556015 is a reply to message #556001] Mon, 30 August 2010 14:37 Go to previous messageGo to next message
Dani Megert is currently offline Dani MegertFriend
Messages: 3802
Registered: July 2009
Senior Member
Michael Moser wrote:
> I am getting an odd (IMHO false) compiler warning re. possible
> dereferentiation of null pointers:
>
> I have a switch statemement where each case handles one possible value
> of an enumeration type and assigns a value (using "= new
> <Constructor>(...)." ) to some variable defined right before the
> switch statement. Following the switch statement there is some common
> code that operates on that variable assigned above.
>
> For some reason I am getting a null-pointer warning on the use of that
> variable although IMHO there is no possible path through that switch
> without assigning a value to the variable. I even added a
> default-clause to the switch to cover all non-matching cases and
> throwing an exception (although I claim that this fragment is
> impossible to reach).
>
> Still, the compiler issues a null-pointer warning. Why?
>
Nope, but best is to file a bug report against JDT Core with a concrete
example rather than prose text.

Dani
> Any idea?
>
> Michael
>
Re: Strange null-pointer warning after switch statement... / false alarm [message #556117 is a reply to message #556015] Mon, 30 August 2010 20:45 Go to previous message
Michael Moser is currently offline Michael MoserFriend
Messages: 914
Registered: July 2009
Senior Member
On Mon, 30 Aug 2010 16:37:16 +0200, Daniel Megert
<daniel_megert@ch.ibm.com> wrote:

>Nope, but best is to file a bug report against JDT Core with a concrete
>example rather than prose text.

Blush! How embarrassing! I should have more faith in Eclipse! There
was indeed one path left, that could end without assignment...

Mea culpa! Apologies,
Michael
Previous Topic:Change a page
Next Topic:How to Install Spring Plugin?
Goto Forum:
  


Current Time: Fri Apr 19 19:04:44 GMT 2024

Powered by FUDForum. Page generated in 0.02783 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top