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; }
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.
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"?
>> 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.
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;
}
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
Thanks a ton! For the answer and the plugin:)
You're certainly welcome, but this inspection is core IDEA, not InspectionGadgets, so someone else gets the credit for this one.
--Dave Griffith
Dave Griffith wrote:
Is it possible to add into this inspection/intention a highlight/lookup
of whatever triggered the "may produce an NPE"?
Mark
Mark Derricutt 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.
You should file a request to JIRA; Dave didn't write that inspection.
Keith Lea wrote:
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"....