false Method invocation may produce java.lang.NullPointerException

Not sure how easy this one is to check for, but IDEA gives a false warning
with the following code. Should I file a Jira request?


public class Test
{
private static String STRING = "abc";
private Object x;
private Object y;

public void setX(Object x) { this.x = x; }

public void setY(Object y) { this.y = y; }

public void test() {
if (x == null)
y = STRING;

if (y == null)
{
String str = x.toString(); <--- x cannot be null here.
}
}
}


2 comments
Comment actions Permalink

you STRING variable could be null as it is not final

0
Comment actions Permalink

x can be null if another thread calls setX.

/Mikael

"Chris Miller" <chris_overseasNOSPAM@hotmail.com> wrote in message
news:a6939bdab41778c8f3ccd3e825a8@news.jetbrains.com...

Not sure how easy this one is to check for, but IDEA gives a false warning
with the following code. Should I file a Jira request?

>
>

public class Test
{
private static String STRING = "abc";
private Object x;
private Object y;

>

public void setX(Object x) { this.x = x; }

>

public void setY(Object y) { this.y = y; }

>

public void test() {
if (x == null)
y = STRING;

>

if (y == null)
{
String str = x.toString(); <--- x cannot be null here.
}
}
}

>



0

Please sign in to leave a comment.