Here below is a code snippet in java.
Collection contextPages = (Collection) getContextPages();
Iterator contextPageIter = contextPages.iterator();
while (contextPageIter.hasNext()) {
Page contextPage = (Page) contextPageIter.next();
String result = contextPage.getResult(); // <-- Null pointer exception here
// Other stuff which this API does.
}
This code has been in production for a while. But for some reason, we hit a null pointer at String result = contextPage.getResult();.
So looks like even though we did a check for hasNext(), the next() method is returning null.
One possibility is that the collection itself has a null, but is it possible that this code could yield to a null pointer in a multi-threaded environment?
contextPages.