Editor warns me that an Object may produce a NPE in caught NullPointerException

Answered

Now, this isn't a serious problem, but why does the editor warn me that this

May produce a NPE?

String item = null;
Scanner scanner = new Scanner(System.in);

if(scanner.nextInt == 1)
{
item = "weapon";
}

try
{ /*Warning \/\/\/ here */
if(item.equals("weapon"))
{
//things....
}
}
catch(NullPointerException e)
{
e.printStackTrace();
}

0
1 comment

Hi. I have raised a ticket for this issue, please follow:

https://youtrack.jetbrains.com/issue/IDEA-196866

0

Please sign in to leave a comment.