#7 Training a model off an empty EventStream NPEs

open
nobody
None
5
2009-05-20
2009-05-20
David R. MacIver
No

The following code will throw an NPE:

import opennlp.maxent.*;

class NPE{
public static void main(String[] args){
EventStream es = new EventStream(){
public boolean hasNext(){ return false; }
public Event nextEvent(){ throw new RuntimeException(); }
};
GIS.trainModel(es, 100, 5);
}
}

This isn't a disaster, as clearly the resulting model isn't going to be very useful so it's quite reasonable to throw some sort of exception, but something a little more enlightening than an NPE would be nice: When I first encountered this it was as the result of a non-empty but small training set in which all the events were discarded, so I was initially quite confused.

Discussion