Program: 118378
Project: 118378
Buggy source:
private void updateNodeOnLink(CreationTool tool){
  try {
    Class toolClass=TargetingTool.class;
    Field targetRequestField=toolClass.getDeclaredField("String_Node_Str");
    Field targetEditpartField=toolClass.getDeclaredField("String_Node_Str");
    targetRequestField.setAccessible(true);
    targetEditpartField.setAccessible(true);
    Request request=(Request)targetRequestField.get(tool);
    EditPart editPart=(EditPart)targetEditpartField.get(tool);
    if ((request instanceof CreateRequest) && readOnly) {
      return;
    }
    if (request instanceof CreateRequest && selectedConnectionPart != null) {
      Object object=((CreateRequest)request).getNewObject();
      if (object instanceof Node) {
        Node node=(Node)object;
        Point originalPoint=((CreateRequest)request).getLocation();
        RootEditPart rep=getViewer().getRootEditPart().getRoot();
        Point viewOriginalPosition=new Point();
        if (rep instanceof ScalableFreeformRootEditPart) {
          ScalableFreeformRootEditPart root=(ScalableFreeformRootEditPart)rep;
          Viewport viewport=(Viewport)root.getFigure();
          viewOriginalPosition=viewport.getViewLocation();
        }
        Point point=new Point(originalPoint.x + viewOriginalPosition.x,originalPoint.y + viewOriginalPosition.y);
        Connection targetConnection=(Connection)selectedConnectionPart.getModel();
        if (targetConnection != null) {
          NodeContainer nodeContainer=null;
          if (node.isJoblet() || node.isMapReduce()) {
            nodeContainer=new JobletContainer(node);
          }
 else {
            nodeContainer=new NodeContainer(node);
          }
          if (getProcess() instanceof Process) {
            CreateNodeContainerCommand createCmd=new CreateNodeContainerCommand((Process)getProcess(),nodeContainer,point);
            execCommandStack(createCmd);
            Node originalTarget=(Node)targetConnection.getTarget();
            EConnectionType connectionType=EConnectionType.FLOW_MAIN;
            if (GlobalServiceRegister.getDefault().isServiceRegistered(ICamelDesignerCoreService.class)) {
              ICamelDesignerCoreService camelService=(ICamelDesignerCoreService)GlobalServiceRegister.getDefault().getService(ICamelDesignerCoreService.class);
              if (camelService.isRouteBuilderNode(node)) {
                connectionType=camelService.getTargetConnectionType(node);
              }
            }
            INodeConnector targetConnector=node.getConnectorFromType(connectionType);
            for (            INodeConnector connector : node.getConnectorsFromType(connectionType)) {
              if (connector.getMaxLinkOutput() != 0) {
                targetConnector=connector;
                break;
              }
            }
            ConnectionCreateCommand.setCreatingConnection(true);
            if (PluginChecker.isJobLetPluginLoaded()) {
              IJobletProviderService service=(IJobletProviderService)GlobalServiceRegister.getDefault().getService(IJobletProviderService.class);
              if (service != null && service.isJobletComponent(targetConnection.getTarget())) {
                if (targetConnection.getTarget() instanceof Node) {
                  NodeContainer jobletContainer=((Node)targetConnection.getTarget()).getNodeContainer();
                  jobletContainer.getInputs().remove(targetConnection);
                }
              }
            }
            ConnectionReconnectCommand cmd2=new ConnectionReconnectCommand(targetConnection);
            cmd2.setNewTarget(node);
            execCommandStack(cmd2);
            List<Object> nodeArgs=null;
            if (connectionType == EConnectionType.ROUTE || connectionType == EConnectionType.ROUTE_ENDBLOCK) {
              nodeArgs=new ArrayList<Object>();
              nodeArgs.add(null);
              nodeArgs.add(ConnectionUtil.generateUniqueConnectionName(connectionType,originalTarget.getProcess(),targetConnector));
              nodeArgs.add(null);
            }
 else {
              nodeArgs=CreateComponentOnLinkHelper.getTargetArgs(targetConnection,node);
            }
            ConnectionCreateCommand nodeCmd=new ConnectionCreateCommand(node,targetConnector.getName(),nodeArgs,false);
            nodeCmd.setTarget(originalTarget);
            execCommandStack(nodeCmd);
            if (node.getOutgoingConnections().size() > 0) {
              if (node.getExternalNode() instanceof MapperExternalNode) {
                CreateComponentOnLinkHelper.setupTMap(node);
              }
              if (originalTarget.getExternalNode() instanceof MapperExternalNode) {
                CreateComponentOnLinkHelper.updateTMap(originalTarget,targetConnection,node.getOutgoingConnections().get(0));
              }
              originalTarget.renameData(targetConnection.getName(),node.getOutgoingConnections().get(0).getName());
            }
            if (!ConnectionCreateCommand.isCreatingConnection()) {
              return;
            }
          }
        }
      }
    }
    if (request instanceof CreateRequest) {
      CreateRequest cRequest=(CreateRequest)request;
      Object newObject=cRequest.getNewObject();
      boolean isNodeInstance=(newObject instanceof Node);
      boolean isNoteInstance=(newObject instanceof Note);
      if (isNodeInstance || isNoteInstance) {
        Point originalPoint=((CreateRequest)request).getLocation();
        RootEditPart rep=getViewer().getRootEditPart().getRoot();
        Point viewOriginalPosition=new Point();
        if (rep instanceof ScalableFreeformRootEditPart) {
          ScalableFreeformRootEditPart root=(ScalableFreeformRootEditPart)rep;
          Viewport viewport=(Viewport)root.getFigure();
          viewOriginalPosition=viewport.getViewLocation();
        }
        Point point=new Point(originalPoint.x + viewOriginalPosition.x,originalPoint.y + viewOriginalPosition.y);
        CreateCommand createCmd=null;
        if (isNodeInstance) {
          Node node=(Node)newObject;
          if (!node.getComponent().getComponentType().equals(EComponentType.JOBLET)) {
            NodeContainer nodeContainer=null;
            if (node.isMapReduce()) {
              nodeContainer=new JobletContainer(node);
            }
 else {
              nodeContainer=new NodeContainer(node);
            }
            createCmd=new CreateNodeContainerCommand((Process)getProcess(),nodeContainer,point);
          }
        }
 else         if (isNoteInstance) {
          createCmd=new CreateNoteCommand((Process)getProcess(),(Note)newObject,point);
        }
        if (createCmd != null) {
          execCommandStack(createCmd);
        }
      }
    }
  }
 catch (  SecurityException e) {
    ExceptionHandler.process(e);
  }
catch (  NoSuchFieldException e) {
    ExceptionHandler.process(e);
  }
catch (  IllegalArgumentException e) {
    ExceptionHandler.process(e);
  }
catch (  IllegalAccessException e) {
    ExceptionHandler.process(e);
  }
}

Fixed version (ground truth):
private void updateNodeOnLink(CreationTool tool){
  try {
    Class toolClass=TargetingTool.class;
    Field targetRequestField=toolClass.getDeclaredField("String_Node_Str");
    Field targetEditpartField=toolClass.getDeclaredField("String_Node_Str");
    targetRequestField.setAccessible(true);
    targetEditpartField.setAccessible(true);
    Request request=(Request)targetRequestField.get(tool);
    EditPart editPart=(EditPart)targetEditpartField.get(tool);
    if ((request instanceof CreateRequest) && readOnly) {
      return;
    }
    if (request instanceof CreateRequest && selectedConnectionPart != null) {
      Object object=((CreateRequest)request).getNewObject();
      if (object instanceof Node) {
        Node node=(Node)object;
        Point originalPoint=((CreateRequest)request).getLocation();
        RootEditPart rep=getViewer().getRootEditPart().getRoot();
        Point viewOriginalPosition=new Point();
        if (rep instanceof ScalableFreeformRootEditPart) {
          ScalableFreeformRootEditPart root=(ScalableFreeformRootEditPart)rep;
          Viewport viewport=(Viewport)root.getFigure();
          viewOriginalPosition=viewport.getViewLocation();
        }
        Point point=new Point(originalPoint.x + viewOriginalPosition.x,originalPoint.y + viewOriginalPosition.y);
        point.x=(int)(point.x / AnimatableZoomManager.currentZoom);
        point.y=(int)(point.y / AnimatableZoomManager.currentZoom);
        Connection targetConnection=(Connection)selectedConnectionPart.getModel();
        if (targetConnection != null) {
          NodeContainer nodeContainer=null;
          if (node.isJoblet() || node.isMapReduce()) {
            nodeContainer=new JobletContainer(node);
          }
 else {
            nodeContainer=new NodeContainer(node);
          }
          if (getProcess() instanceof Process) {
            CreateNodeContainerCommand createCmd=new CreateNodeContainerCommand((Process)getProcess(),nodeContainer,point);
            execCommandStack(createCmd);
            Node originalTarget=(Node)targetConnection.getTarget();
            EConnectionType connectionType=EConnectionType.FLOW_MAIN;
            if (GlobalServiceRegister.getDefault().isServiceRegistered(ICamelDesignerCoreService.class)) {
              ICamelDesignerCoreService camelService=(ICamelDesignerCoreService)GlobalServiceRegister.getDefault().getService(ICamelDesignerCoreService.class);
              if (camelService.isRouteBuilderNode(node)) {
                connectionType=camelService.getTargetConnectionType(node);
              }
            }
            INodeConnector targetConnector=node.getConnectorFromType(connectionType);
            for (            INodeConnector connector : node.getConnectorsFromType(connectionType)) {
              if (connector.getMaxLinkOutput() != 0) {
                targetConnector=connector;
                break;
              }
            }
            ConnectionCreateCommand.setCreatingConnection(true);
            if (PluginChecker.isJobLetPluginLoaded()) {
              IJobletProviderService service=(IJobletProviderService)GlobalServiceRegister.getDefault().getService(IJobletProviderService.class);
              if (service != null && service.isJobletComponent(targetConnection.getTarget())) {
                if (targetConnection.getTarget() instanceof Node) {
                  NodeContainer jobletContainer=((Node)targetConnection.getTarget()).getNodeContainer();
                  jobletContainer.getInputs().remove(targetConnection);
                }
              }
            }
            ConnectionReconnectCommand cmd2=new ConnectionReconnectCommand(targetConnection);
            cmd2.setNewTarget(node);
            execCommandStack(cmd2);
            List<Object> nodeArgs=null;
            if (connectionType == EConnectionType.ROUTE || connectionType == EConnectionType.ROUTE_ENDBLOCK) {
              nodeArgs=new ArrayList<Object>();
              nodeArgs.add(null);
              nodeArgs.add(ConnectionUtil.generateUniqueConnectionName(connectionType,originalTarget.getProcess(),targetConnector));
              nodeArgs.add(null);
            }
 else {
              nodeArgs=CreateComponentOnLinkHelper.getTargetArgs(targetConnection,node);
            }
            ConnectionCreateCommand nodeCmd=new ConnectionCreateCommand(node,targetConnector.getName(),nodeArgs,false);
            nodeCmd.setTarget(originalTarget);
            execCommandStack(nodeCmd);
            if (node.getOutgoingConnections().size() > 0) {
              if (node.getExternalNode() instanceof MapperExternalNode) {
                CreateComponentOnLinkHelper.setupTMap(node);
              }
              if (originalTarget.getExternalNode() instanceof MapperExternalNode) {
                CreateComponentOnLinkHelper.updateTMap(originalTarget,targetConnection,node.getOutgoingConnections().get(0));
              }
              originalTarget.renameData(targetConnection.getName(),node.getOutgoingConnections().get(0).getName());
            }
            if (!ConnectionCreateCommand.isCreatingConnection()) {
              return;
            }
          }
        }
      }
    }
    if (request instanceof CreateRequest) {
      CreateRequest cRequest=(CreateRequest)request;
      Object newObject=cRequest.getNewObject();
      boolean isNodeInstance=(newObject instanceof Node);
      boolean isNoteInstance=(newObject instanceof Note);
      if (isNodeInstance || isNoteInstance) {
        Point originalPoint=((CreateRequest)request).getLocation();
        RootEditPart rep=getViewer().getRootEditPart().getRoot();
        Point viewOriginalPosition=new Point();
        if (rep instanceof ScalableFreeformRootEditPart) {
          ScalableFreeformRootEditPart root=(ScalableFreeformRootEditPart)rep;
          Viewport viewport=(Viewport)root.getFigure();
          viewOriginalPosition=viewport.getViewLocation();
        }
        Point point=new Point(originalPoint.x + viewOriginalPosition.x,originalPoint.y + viewOriginalPosition.y);
        point.x=(int)(point.x / AnimatableZoomManager.currentZoom);
        point.y=(int)(point.y / AnimatableZoomManager.currentZoom);
        CreateCommand createCmd=null;
        if (isNodeInstance) {
          Node node=(Node)newObject;
          if (!node.getComponent().getComponentType().equals(EComponentType.JOBLET)) {
            NodeContainer nodeContainer=null;
            if (node.isMapReduce()) {
              nodeContainer=new JobletContainer(node);
            }
 else {
              nodeContainer=new NodeContainer(node);
            }
            createCmd=new CreateNodeContainerCommand((Process)getProcess(),nodeContainer,point);
          }
        }
 else         if (isNoteInstance) {
          createCmd=new CreateNoteCommand((Process)getProcess(),(Note)newObject,point);
        }
        if (createCmd != null) {
          execCommandStack(createCmd);
        }
      }
    }
  }
 catch (  SecurityException e) {
    ExceptionHandler.process(e);
  }
catch (  NoSuchFieldException e) {
    ExceptionHandler.process(e);
  }
catch (  IllegalArgumentException e) {
    ExceptionHandler.process(e);
  }
catch (  IllegalAccessException e) {
    ExceptionHandler.process(e);
  }
}