Threading issues
Because regular lists are being used and those lists are cleared instead of e.g. instantiating a new list, I run into a bunch of errors like these:
java.util.ConcurrentModificationException: null
at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1380)
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:512)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:502)
at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:151)
at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:174)
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:418)
Either use CopyOnWriteArrayList or set new Array lists instead of clearing the old ones
Or wrap them in a Collections.synchronizedList(new ArrayList<>());
No not synchronised lists :(. That makes everything unnecessary slow. Instead of a clean a new object would be better since object creation is a lot cheeper than synchronising everything. GC should take care of the old object of the user does not hang on to it
Or just wrap every return in new ArrayList<>() is better than synchronising them
Syncd lists dont stop concurrent modifications anyway
Oh, mm. I thought they were expressly made for that. It's a slow implementation, that is true. But we don't have that many concurrent modifications (at most one) so the lock wouldn't be very long.
You should maybe consider using a ConcurrentLinkedQueue (https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ConcurrentLinkedQueue.html)