Buggy code:
public class WonWebSocketHandler extends TextWebSocketHandler implements InitializingBean , OwnerApplicationServiceCallback { private final Logger logger = LoggerFactory . getLogger ( getClass ( ) ) ; @ Autowired private OwnerApplicationService ownerApplicationService ; @ Autowired private WebSocketSessionService webSocketSessionService ; @ Autowired private UserRepository userRepository ; @ Autowired private UserNeedRepository userNeedRepository ; @ Autowired SessionRepository sessionRepository ; @ Autowired private WonOwnerMailSender emailSender ; @ Override public void afterPropertiesSet ( ) throws Exception { } @ Override public void afterConnectionEstablished ( final WebSocketSession session ) throws Exception { } @ Override public void afterConnectionClosed ( final WebSocketSession session , final CloseStatus status ) throws Exception { } @ Override @ Transactional ( propagation = Propagation . SUPPORTS ) public void handleTextMessage ( WebSocketSession session , TextMessage message ) throws IOException { } private void updateSession ( final WebSocketSession session ) { } @ Override @ Transactional ( propagation = Propagation . SUPPORTS ) public void onMessage ( final WonMessage wonMessage ) { } private void notifyPerEmail ( final User user , final URI needUri , final WonMessage wonMessage ) { <START_BUG> if ( user != null ) { <END_BUG> return ; } UserNeed userNeed = getNeedOfUser ( user , needUri ) ; if ( userNeed == null ) { return ; } try { switch ( wonMessage . getMessageType ( ) ) { case OPEN : if ( userNeed . isConversations ( ) ) { emailSender . sendNotificationMessage ( user . getEmail ( ) , "Conversation<seq2seq4repair_space>Message" , wonMessage . getReceiverNeedURI ( ) . toString ( ) ) ; } return ; case CONNECTION_MESSAGE : if ( userNeed . isConversations ( ) ) { emailSender . sendNotificationMessage ( user . getEmail ( ) , "Conversation<seq2seq4repair_space>Message" , wonMessage . getReceiverNeedURI ( ) . toString ( ) ) ; } return ; case CONNECT : if ( userNeed . isRequests ( ) ) { emailSender . sendNotificationMessage ( user . getEmail ( ) , "Conversation<seq2seq4repair_space>Request" , wonMessage . getReceiverNeedURI ( ) . toString ( ) ) ; } return ; case HINT_MESSAGE : if ( userNeed . isRequests ( ) ) { emailSender . sendNotificationMessage ( user . getEmail ( ) , "Match" , wonMessage . getReceiverNeedURI ( ) . toString ( ) ) ; } return ; case CLOSE : return ; default : return ; } } catch ( MailException ex ) { logger . error ( "Email<seq2seq4repair_space>could<seq2seq4repair_space>not<seq2seq4repair_space>be<seq2seq4repair_space>sent" , ex ) ; } } private Set < WebSocketSession > findWebSocketSessionsForWonMessage ( final WonMessage wonMessage , URI needUri , User user ) { } private void removeClosedSessions ( final Set < WebSocketSession > webSocketSessions , final URI needUri ) { } private void removeClosedSessions ( final Set < WebSocketSession > webSocketSessions , final User user ) { } private User getUserForWonMessage ( final WonMessage wonMessage ) { } private UserNeed getNeedOfUser ( final User user , final URI needUri ) { } private synchronized void sendMessageForSession ( final WonMessage wonMessage , final WebSocketMessage < String > webSocketMessage , final WebSocketSession session , URI needUri , User user ) { } private void saveNeedUriWithUser ( final WonMessage wonMessage , final WebSocketSession session ) { } private User getUserForSession ( final WebSocketSession session ) { } public void setOwnerApplicationService ( final OwnerApplicationService ownerApplicationService ) { } }

Fix:
if ( user == null ) {