7 comments
Comment actions Permalink

Oops, the Code button submits? Anyway, IDEA says the line students.add(examinee); may produce a NPE. I don't see how. Am I missing something?

private List findStudentsFromIds(final String[] selectedStudentIds, final List entityRoster)
{
List students = null;
if (selectedStudentIds != null && selectedStudentIds.length > 0)
{
students = new ArrayList(selectedStudentIds.length);
for (int i = 0; i < selectedStudentIds.length; i++)
{
boolean found = false;
String studentId = selectedStudentIds+;
for (Iterator iterator = entityRoster.iterator(); iterator.hasNext() && !found;)
{
Examinee examinee = (Examinee) iterator.next();
if (examinee.getExamineeID() == Long.parseLong(studentId))
{
students.add(examinee);
found = true;
}
}
if (!found) //this shouldn't happen but...
{
LOG.error("Student not found.");
students = null;
}
}
}
return students;
}

0
Comment actions Permalink

Nope, it's exactly correct. That assignment of "students = null" down at the bottom could come around to bite you on the next iteration of the outer for loop.

--Dave Griffith

0
Comment actions Permalink

Thanks a ton! For the answer and the plugin:)

0
Comment actions Permalink


You're certainly welcome, but this inspection is core IDEA, not InspectionGadgets, so someone else gets the credit for this one.

--Dave Griffith

0
Comment actions Permalink

Dave Griffith wrote:

Nope, it's exactly correct. That assignment of "students = null"
down at the bottom could come around to bite you on the next
iteration of the outer for loop.


Is it possible to add into this inspection/intention a highlight/lookup
of whatever triggered the "may produce an NPE"?

Mark

0
Comment actions Permalink

Mark Derricutt wrote:

Dave Griffith wrote:

>> Nope, it's exactly correct. That assignment of "students = null"
>> down at the bottom could come around to bite you on the next
>> iteration of the outer for loop.


Is it possible to add into this inspection/intention a highlight/lookup
of whatever triggered the "may produce an NPE"?

Mark


You should file a request to JIRA; Dave didn't write that inspection.

0
Comment actions Permalink

Keith Lea wrote:

You should file a request to JIRA; Dave didn't write that inspection.


Filed as http://jetbrains.net/jira/browse/IDEA-4309

I added a bunch of "most likely to be ignored, but definitely discussed"
ideas on quick fixes and "smart solutions"....

0

Please sign in to leave a comment.