Index: lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/web/controller/LearningWebsocketServer.java =================================================================== diff -u -r18a207719c2aa30f683987fd0bb9176521b704de -rb8797193dabd790bbeb45f08fbbae52f0f07bf6d --- lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/web/controller/LearningWebsocketServer.java (.../LearningWebsocketServer.java) (revision 18a207719c2aa30f683987fd0bb9176521b704de) +++ lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/web/controller/LearningWebsocketServer.java (.../LearningWebsocketServer.java) (revision b8797193dabd790bbeb45f08fbbae52f0f07bf6d) @@ -56,23 +56,24 @@ try { // websocket communication bypasses standard HTTP filters, so Hibernate session needs to be initialised manually HibernateSessionManager.openSession(); - + Iterator>> entryIterator = LearningWebsocketServer.websockets.entrySet() .iterator(); // go through activities and update registered learners with reports and vote count while (entryIterator.hasNext()) { Entry> entry = entryIterator.next(); Long toolSessionId = entry.getKey(); - // if all learners left the activity, remove the obsolete mapping + Set sessionWebsockets = entry.getValue(); - if (sessionWebsockets.isEmpty()) { + ScratchieSession toolSession = LearningWebsocketServer.getScratchieService() + .getScratchieSessionBySessionId(toolSessionId); + // if all learners left the activity or session is missing, remove the obsolete mapping + if (sessionWebsockets.isEmpty() || toolSession == null) { entryIterator.remove(); LearningWebsocketServer.cache.remove(toolSessionId); continue; } - ScratchieSession toolSession = LearningWebsocketServer.getScratchieService() - .getScratchieSessionBySessionId(toolSessionId); boolean timeLimitUp = false; boolean scratchingFinished = toolSession.isScratchingFinished(); // is Scratchie time limited? @@ -126,6 +127,8 @@ } catch (IllegalStateException e) { // do nothing as server is probably shutting down and we could not obtain Hibernate session } catch (Exception e) { + //TODO remove this once NullPointerExceptions do not show anymore in logs + e.printStackTrace(); // error caught, but carry on log.error("Error in Scratchie worker thread", e); } finally {