incorrect highlighting of May Produce NPE

prevSeg.direction() is highlighted as "May produce NPE" here:

Object prevSeg=null;
for ...
{
if (dseg.equals(prevSeg))
{
if (dseg.direction()==prevSeg.direction())


But prevSeg cannot be null, as dseg.equals(prevSeg),
which will never be true if prevSeg is null, otherwise dseg needed to be null,
which would produce NPE.

2 comments
Comment actions Permalink

Hello Michael,

MD> prevSeg.direction() is highlighted as "May produce NPE" here:
MD>
MD> Object prevSeg=null;
MD> for ...
MD> {
MD> if (dseg.equals(prevSeg))
MD> {
MD> if (dseg.direction()==prevSeg.direction())
MD> But prevSeg cannot be null, as dseg.equals(prevSeg),
MD> which will never be true if prevSeg is null, otherwise dseg needed
MD> to be null, which would produce NPE.

IntelliJ IDEA is not currently smart enough to know the semantics of the
equals() method (which may actually differ for your overridden class).

--
Dmitry Jemerov
Software Developer
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0
Comment actions Permalink

ok, I see your point - although I don't think it makes sense for any equals method to return true for parameter null... but I may be wrong here ;)

0

Please sign in to leave a comment.