The code:
PerClassWork[] worksFromEvents = new PerClassWork[byClass.size()]; worksFromEvents = byClass.values().toArray( worksFromEvents );
The first array instantiation is useless, since it is erased on the very next line.