For some reason, I'm getting java.lang.IllegalStateException: null exception from the method that was working just fine before. I don't think I made any changes on this. It just suddenly stopped working and it doesn't throw an error on every entry, just the one that is 4. in the list. I can't even see anything different on that entry, it has all the properties it's supposed to have.
Iterator<Class> iter = contacts.iterator();
while (iter.hasNext()){
Class holder = iter.next();
try {
if(dateNow.isBefore(holder.getStartDate())){
iter.remove();
}if(dateNow.isAfter(holder.getEndDate())){
iter.remove();
}else{
boolean status = checkStatus(holder);
if(!status){
iter.remove();
}
}
}catch (NullPointerException e) {
//No end-date or start date
boolean status = checkStatus(holder);
if(!status){
iter.remove();
}
else if(dateNow.isBefore(holder.getStartDate())){
iter.remove();
}
}
}
is throwing this error. My only reason to use an iterator is that I can remove items while iterating it.
if(!status){
iter.remove();
}
is the spesific line throwing the error, iter.remove() part. status is false, as it should.
thanks for any help.