Program: 72216
Project: 72216
Buggy source:
protected void handleDrop(){
  updateTargetRequest();
  updateTargetEditPart();
  if (DNDService.getInstance().performDrop(TemplateTransfer.getInstance().getTemplate(),getTargetEditPart(),DND.DROP_DEFAULT,new DNDLocation(getDropLocation()))) {
    return;
  }
  boolean isScalarparameter=false;
  boolean isResultSetColumn=false;
  boolean isEmbeddImage=false;
  final Object template=TemplateTransfer.getInstance().getTemplate();
  Assert.isNotNull(template);
  Assert.isTrue(handleValidateDrag(template));
  AbstractToolHandleExtends preHandle=null;
  String transName=null;
  if (template instanceof String) {
    PaletteEntryExtension[] entries=EditpartExtensionManager.getPaletteEntries();
    if (template.toString().startsWith(IReportElementConstants.REPORT_ELEMENT_EXTENDED)) {
      String extensionName=template.toString().substring(IReportElementConstants.REPORT_ELEMENT_EXTENDED.length());
      for (int i=0; i < entries.length; i++) {
        if (entries[i].getItemName().equals(extensionName)) {
          try {
            CommandUtils.setVariable("String_Node_Str",getTargetEditPart());
            CommandUtils.setVariable("String_Node_Str",getTargetRequest());
            getCreateRequest().getExtendedData().put(DesignerConstants.KEY_NEWOBJECT,entries[i].executeCreate());
            selectAddedObject();
            return;
          }
 catch (          Exception e) {
            ExceptionHandler.handle(e);
          }
        }
      }
    }
    transName=TRANS_LABEL_CREATE_ELEMENT;
    preHandle=BasePaletteFactory.getAbstractToolHandleExtendsFromPaletteName(template);
  }
 else   if (handleValidateInsert(template)) {
    transName=InsertInLayoutAction.DISPLAY_TEXT;
    Object objectType=getFactory(template).getObjectType();
    if (objectType instanceof DataSetHandle) {
      preHandle=new DataSetToolExtends();
    }
 else     if (objectType instanceof DataSetItemModel) {
      preHandle=new DataSetColumnToolExtends();
    }
 else     if (objectType instanceof ResultSetColumnHandle) {
      isResultSetColumn=true;
      preHandle=new DataSetColumnToolExtends();
    }
 else     if (objectType instanceof ScalarParameterHandle) {
      isScalarparameter=true;
      preHandle=new ParameterToolExtends();
    }
 else     if (objectType instanceof DimensionHandle) {
      preHandle=new DimensionHandleToolExtends();
    }
 else     if (objectType instanceof MeasureHandle) {
      preHandle=new MeasureHandleToolExtends();
    }
  }
 else   if (handleValidateLibrary(template)) {
    Object dragObj=getSingleTransferData(template);
    if (dragObj instanceof EmbeddedImageHandle) {
      isEmbeddImage=true;
      preHandle=new ImageToolExtends();
    }
 else     preHandle=new LibraryElementsToolHandleExtends((DesignElementHandle)dragObj);
  }
 else   if (handleValidateOutline(template)) {
    Object dragObj=getSingleTransferData(template);
    if (dragObj instanceof EmbeddedImageHandle) {
      isEmbeddImage=true;
      preHandle=new ImageToolExtends();
    }
  }
  if (preHandle != null) {
    CommandStack stack=SessionHandleAdapter.getInstance().getCommandStack();
    stack.startTrans(transName);
    preHandle.setRequest(this.getCreateRequest());
    preHandle.setTargetEditPart(getTargetEditPart());
    if (isEmbeddImage) {
      Object dragObj=getSingleTransferData(template);
      if (dragObj instanceof EmbeddedImageHandle) {
        ModuleHandle moduleHandle=SessionHandleAdapter.getInstance().getReportDesignHandle();
        LibraryHandle library=(LibraryHandle)((EmbeddedImageHandle)dragObj).getElementHandle().getRoot();
        try {
          if (UIUtil.includeLibrary(moduleHandle,library)) {
            EmbeddedImage image=StructureFactory.newEmbeddedImageFrom((EmbeddedImageHandle)dragObj,moduleHandle);
            DNDUtil.addEmbeddedImageHandle(getTargetEditPart().getModel(),image);
          }
        }
 catch (        Exception e) {
          ExceptionHandler.handle(e);
        }
      }
    }
    Command command=this.getCommand();
    if (command != null && command.canExecute()) {
      if (!(preHandle.preHandleMouseUp())) {
        stack.rollback();
        return;
      }
    }
    boolean isTheme=checkTheme(preHandle,getSingleTransferData(template));
    if (!isTheme) {
      super.handleDrop();
      if (!preHandle.postHandleCreation()) {
        stack.rollback();
        return;
      }
      if (isScalarparameter || isResultSetColumn) {
        Request request=new Request(ReportRequest.CREATE_SCALARPARAMETER_OR_RESULTSETCOLUMN);
        selectAddedObject(request);
      }
 else       if (isEmbeddImage) {
        Object dragObj=getSingleTransferData(template);
        final Object model=getCreateRequest().getExtendedData().get(DesignerConstants.KEY_NEWOBJECT);
        try {
          ((ImageHandle)model).setImageName(((EmbeddedImageHandle)dragObj).getName());
        }
 catch (        SemanticException e) {
          ExceptionHandler.handle(e);
        }
        Request request=new Request(ReportRequest.SELECTION);
        selectAddedObject(request);
      }
 else       selectAddedObject();
    }
    stack.commit();
  }
}

Fixed version (ground truth):
protected void handleDrop(){
  updateTargetRequest();
  updateTargetEditPart();
  if (DNDService.getInstance().performDrop(TemplateTransfer.getInstance().getTemplate(),getTargetEditPart(),DND.DROP_DEFAULT,new DNDLocation(getDropLocation()))) {
    return;
  }
  boolean isScalarparameter=false;
  boolean isResultSetColumn=false;
  boolean isEmbeddImage=false;
  final Object template=TemplateTransfer.getInstance().getTemplate();
  Assert.isNotNull(template);
  Assert.isTrue(handleValidateDrag(template));
  AbstractToolHandleExtends preHandle=null;
  String transName=null;
  if (template instanceof String) {
    PaletteEntryExtension[] entries=EditpartExtensionManager.getPaletteEntries();
    if (template.toString().startsWith(IReportElementConstants.REPORT_ELEMENT_EXTENDED)) {
      String extensionName=template.toString().substring(IReportElementConstants.REPORT_ELEMENT_EXTENDED.length());
      for (int i=0; i < entries.length; i++) {
        if (entries[i].getItemName().equals(extensionName)) {
          try {
            CommandUtils.setVariable("String_Node_Str",getTargetEditPart());
            CommandUtils.setVariable("String_Node_Str",getTargetRequest());
            getCreateRequest().getExtendedData().put(DesignerConstants.KEY_NEWOBJECT,entries[i].executeCreate());
            selectAddedObject();
            return;
          }
 catch (          Exception e) {
            ExceptionHandler.handle(e);
          }
        }
      }
    }
    transName=TRANS_LABEL_CREATE_ELEMENT;
    preHandle=BasePaletteFactory.getAbstractToolHandleExtendsFromPaletteName(template);
  }
 else   if (handleValidateInsert(template)) {
    transName=InsertInLayoutAction.DISPLAY_TEXT;
    Object objectType=getFactory(template).getObjectType();
    if (objectType instanceof DataSetHandle) {
      preHandle=new DataSetToolExtends();
    }
 else     if (objectType instanceof DataSetItemModel) {
      preHandle=new DataSetColumnToolExtends();
    }
 else     if (objectType instanceof ResultSetColumnHandle) {
      isResultSetColumn=true;
      preHandle=new DataSetColumnToolExtends();
    }
 else     if (objectType instanceof ScalarParameterHandle) {
      isScalarparameter=true;
      preHandle=new ParameterToolExtends();
    }
 else     if (objectType instanceof DimensionHandle) {
      preHandle=new DimensionHandleToolExtends();
    }
 else     if (objectType instanceof MeasureHandle) {
      preHandle=new MeasureHandleToolExtends();
    }
  }
 else   if (handleValidateLibrary(template)) {
    Object dragObj=getSingleTransferData(template);
    if (dragObj instanceof EmbeddedImageHandle) {
      isEmbeddImage=true;
      preHandle=new ImageToolExtends();
    }
 else     preHandle=new LibraryElementsToolHandleExtends((DesignElementHandle)dragObj);
  }
 else   if (handleValidateOutline(template)) {
    Object dragObj=getSingleTransferData(template);
    if (dragObj instanceof EmbeddedImageHandle) {
      isEmbeddImage=true;
      preHandle=new ImageToolExtends();
    }
  }
  if (preHandle != null) {
    CommandStack stack=SessionHandleAdapter.getInstance().getCommandStack();
    stack.startTrans(transName);
    preHandle.setRequest(this.getCreateRequest());
    preHandle.setTargetEditPart(getTargetEditPart());
    if (isEmbeddImage) {
      Object dragObj=getSingleTransferData(template);
      if (dragObj instanceof EmbeddedImageHandle) {
        if (((EmbeddedImageHandle)dragObj).getElementHandle().getRoot() instanceof LibraryHandle) {
          ModuleHandle moduleHandle=SessionHandleAdapter.getInstance().getReportDesignHandle();
          LibraryHandle library=(LibraryHandle)((EmbeddedImageHandle)dragObj).getElementHandle().getRoot();
          try {
            if (UIUtil.includeLibrary(moduleHandle,library)) {
              EmbeddedImage image=StructureFactory.newEmbeddedImageFrom((EmbeddedImageHandle)dragObj,moduleHandle);
              DNDUtil.addEmbeddedImageHandle(getTargetEditPart().getModel(),image);
            }
          }
 catch (          Exception e) {
            ExceptionHandler.handle(e);
          }
        }
      }
    }
    Command command=this.getCommand();
    if (command != null && command.canExecute()) {
      if (!(preHandle.preHandleMouseUp())) {
        stack.rollback();
        return;
      }
    }
    boolean isTheme=checkTheme(preHandle,getSingleTransferData(template));
    if (!isTheme) {
      super.handleDrop();
      if (!preHandle.postHandleCreation()) {
        stack.rollback();
        return;
      }
      if (isScalarparameter || isResultSetColumn) {
        Request request=new Request(ReportRequest.CREATE_SCALARPARAMETER_OR_RESULTSETCOLUMN);
        selectAddedObject(request);
      }
 else       if (isEmbeddImage) {
        Object dragObj=getSingleTransferData(template);
        final Object model=getCreateRequest().getExtendedData().get(DesignerConstants.KEY_NEWOBJECT);
        try {
          ((ImageHandle)model).setImageName(((EmbeddedImageHandle)dragObj).getName());
        }
 catch (        SemanticException e) {
          ExceptionHandler.handle(e);
        }
        Request request=new Request(ReportRequest.SELECTION);
        selectAddedObject(request);
      }
 else       selectAddedObject();
    }
    stack.commit();
  }
}