Program: 58342
Project: 58342
Buggy source:
/** 
 * Adds a mechanism to select nodes by clicking on them. <p> Holding the <b>control</b> key while clicking will add to the existing selection. </p>
 */
private void addClickSelectionMechanism(){
  for (  final GNode node : model.getNodes()) {
    final GNodeSkin nodeSkin=skinLookup.lookupNode(node);
    final Region nodeRegion=nodeSkin.getRoot();
    final EventHandler<MouseEvent> oldNodePressedHandler=nodePressedHandlers.get(node);
    final EventHandler<MouseEvent> oldNodeReleasedHandler=nodeReleasedHandlers.get(node);
    if (oldNodePressedHandler != null) {
      nodeRegion.removeEventHandler(MouseEvent.MOUSE_PRESSED,oldNodePressedHandler);
    }
    if (oldNodeReleasedHandler != null) {
      nodeRegion.removeEventHandler(MouseEvent.MOUSE_RELEASED,oldNodeReleasedHandler);
    }
    final EventHandler<MouseEvent> newNodePressedHandler=event -> handleNodePressed(event,node);
    final EventHandler<MouseEvent> newNodeReleasedHandler=event -> handleNodeReleased(event,node);
    nodeRegion.addEventHandler(MouseEvent.MOUSE_PRESSED,newNodePressedHandler);
    nodeRegion.addEventHandler(MouseEvent.MOUSE_RELEASED,newNodeReleasedHandler);
    nodePressedHandlers.put(node,newNodePressedHandler);
    nodeReleasedHandlers.put(node,newNodeReleasedHandler);
    for (    final GConnector connector : node.getConnectors()) {
      final Node connectorRoot=skinLookup.lookupConnector(connector).getRoot();
      final EventHandler<MouseEvent> oldConnectorPressedHandler=connectorPressedHandlers.get(connector);
      if (oldConnectorPressedHandler != null) {
        connectorRoot.removeEventHandler(MouseEvent.MOUSE_PRESSED,oldConnectorPressedHandler);
      }
      final EventHandler<MouseEvent> newConnectorPressedHandler=event -> handleConnectorPressed(event);
      connectorRoot.addEventHandler(MouseEvent.MOUSE_PRESSED,newConnectorPressedHandler);
      connectorPressedHandlers.put(connector,newConnectorPressedHandler);
    }
  }
  for (  final GConnection connection : model.getConnections()) {
    for (    final GJoint joint : connection.getJoints()) {
      final GJointSkin jointSkin=skinLookup.lookupJoint(joint);
      final Region jointRegion=jointSkin.getRoot();
      final EventHandler<MouseEvent> oldJointPressedHandler=nodePressedHandlers.get(joint);
      final EventHandler<MouseEvent> oldJointReleasedHandler=nodeReleasedHandlers.get(joint);
      if (oldJointPressedHandler != null) {
        jointRegion.removeEventHandler(MouseEvent.MOUSE_PRESSED,oldJointPressedHandler);
      }
      if (oldJointReleasedHandler != null) {
        jointRegion.removeEventHandler(MouseEvent.MOUSE_RELEASED,oldJointReleasedHandler);
      }
      final EventHandler<MouseEvent> newJointPressedHandler=event -> handleJointPressed(event,joint);
      final EventHandler<MouseEvent> newJointReleasedHandler=event -> handleJointReleased(event,joint);
      jointRegion.addEventHandler(MouseEvent.MOUSE_PRESSED,newJointPressedHandler);
      jointRegion.addEventHandler(MouseEvent.MOUSE_RELEASED,newJointReleasedHandler);
      jointPressedHandlers.put(joint,newJointPressedHandler);
      jointReleasedHandlers.put(joint,newJointReleasedHandler);
    }
  }
}

Fixed version (ground truth):
/** 
 * Adds a mechanism to select nodes by clicking on them. <p> Holding the <b>control</b> key while clicking will add to the existing selection. </p>
 */
private void addClickSelectionMechanism(){
  for (  final GNode node : model.getNodes()) {
    final Region nodeRegion=skinLookup.lookupNode(node).getRoot();
    final EventHandler<MouseEvent> oldNodePressedHandler=nodePressedHandlers.get(node);
    final EventHandler<MouseEvent> oldNodeReleasedHandler=nodeReleasedHandlers.get(node);
    if (oldNodePressedHandler != null) {
      nodeRegion.removeEventHandler(MouseEvent.MOUSE_PRESSED,oldNodePressedHandler);
    }
    if (oldNodeReleasedHandler != null) {
      nodeRegion.removeEventHandler(MouseEvent.MOUSE_RELEASED,oldNodeReleasedHandler);
    }
    final EventHandler<MouseEvent> newNodePressedHandler=event -> handleNodePressed(event,node);
    final EventHandler<MouseEvent> newNodeReleasedHandler=event -> handleNodeReleased(event,node);
    nodeRegion.addEventHandler(MouseEvent.MOUSE_PRESSED,newNodePressedHandler);
    nodeRegion.addEventHandler(MouseEvent.MOUSE_RELEASED,newNodeReleasedHandler);
    nodePressedHandlers.put(node,newNodePressedHandler);
    nodeReleasedHandlers.put(node,newNodeReleasedHandler);
    for (    final GConnector connector : node.getConnectors()) {
      final Node connectorRoot=skinLookup.lookupConnector(connector).getRoot();
      final EventHandler<MouseEvent> oldConnectorPressedHandler=connectorPressedHandlers.get(connector);
      if (oldConnectorPressedHandler != null) {
        connectorRoot.removeEventHandler(MouseEvent.MOUSE_PRESSED,oldConnectorPressedHandler);
      }
      final EventHandler<MouseEvent> newConnectorPressedHandler=event -> handleConnectorPressed(event);
      connectorRoot.addEventHandler(MouseEvent.MOUSE_PRESSED,newConnectorPressedHandler);
      connectorPressedHandlers.put(connector,newConnectorPressedHandler);
    }
  }
  for (  final GConnection connection : model.getConnections()) {
    for (    final GJoint joint : connection.getJoints()) {
      final Region jointRegion=skinLookup.lookupJoint(joint).getRoot();
      final EventHandler<MouseEvent> oldJointPressedHandler=jointPressedHandlers.get(joint);
      final EventHandler<MouseEvent> oldJointReleasedHandler=jointReleasedHandlers.get(joint);
      if (oldJointPressedHandler != null) {
        jointRegion.removeEventHandler(MouseEvent.MOUSE_PRESSED,oldJointPressedHandler);
      }
      if (oldJointReleasedHandler != null) {
        jointRegion.removeEventHandler(MouseEvent.MOUSE_RELEASED,oldJointReleasedHandler);
      }
      final EventHandler<MouseEvent> newJointPressedHandler=event -> handleJointPressed(event,joint);
      final EventHandler<MouseEvent> newJointReleasedHandler=event -> handleJointReleased(event,joint);
      jointRegion.addEventHandler(MouseEvent.MOUSE_PRESSED,newJointPressedHandler);
      jointRegion.addEventHandler(MouseEvent.MOUSE_RELEASED,newJointReleasedHandler);
      jointPressedHandlers.put(joint,newJointPressedHandler);
      jointReleasedHandlers.put(joint,newJointReleasedHandler);
    }
  }
}