Program: 101131
Project: 101131
Buggy source:
public void execute(final Event<UIAddGadgetForm> event) throws Exception {
  WebuiRequestContext context=event.getRequestContext();
  UIAddGadgetForm uiForm=event.getSource();
  UIDashboard uiDashboard=uiForm.getAncestorOfType(UIDashboard.class);
  UIDashboardContainer uiContainer=uiDashboard.getChild(UIDashboardContainer.class);
  GadgetRegistryService service=uiForm.getApplicationComponent(GadgetRegistryService.class);
  String url=uiForm.getUIStringInput(FIELD_URL).getValue();
  try {
    new URL(url);
  }
 catch (  Exception e) {
    UIApplication uiApplication=context.getUIApplication();
    uiApplication.addMessage(new ApplicationMessage("String_Node_Str",null));
    context.addUIComponentToUpdateByAjax(uiApplication.getUIPopupMessages());
    return;
  }
  Gadget gadget;
  UIGadget uiGadget;
  try {
    String name="String_Node_Str" + url.hashCode();
    gadget=GadgetUtil.toGadget(name,url,false);
    service.saveGadget(gadget);
    StringBuilder windowId=new StringBuilder(PortalConfig.USER_TYPE);
    windowId.append("String_Node_Str").append(context.getRemoteUser());
    windowId.append("String_Node_Str").append(gadget.getName()).append('/');
    uiGadget=uiForm.createUIComponent(context,UIGadget.class,null,null);
    uiGadget.setId(Integer.toString(uiGadget.hashCode() + 1));
    windowId.append(uiGadget.hashCode());
    uiGadget.setApplicationInstanceId(windowId.toString());
  }
 catch (  Exception e) {
    gadget=service.getGadget("String_Node_Str");
    StringBuilder windowId=new StringBuilder(PortalConfig.USER_TYPE);
    windowId.append("String_Node_Str").append(context.getRemoteUser());
    windowId.append("String_Node_Str").append(gadget.getName()).append('/');
    uiGadget=uiForm.createUIComponent(context,UIGadget.class,null,null);
    uiGadget.setId(Integer.toString(url.hashCode() + 1));
    windowId.append(url.hashCode());
    uiGadget.setApplicationInstanceId(windowId.toString());
    String params="String_Node_Str" + url + "String_Node_Str";
    UserGadgetStorage userGadgetStorage=uiForm.getApplicationComponent(UserGadgetStorage.class);
    userGadgetStorage.save(Util.getPortalRequestContext().getRemoteUser(),gadget.getName(),"String_Node_Str" + url.hashCode(),UIGadget.PREF_KEY,params);
  }
  uiContainer.addUIGadget(uiGadget,0,0);
  uiContainer.save();
  uiForm.reset();
  context.addUIComponentToUpdateByAjax(uiForm);
  context.addUIComponentToUpdateByAjax(uiContainer);
}

Fixed version (ground truth):
public void execute(final Event<UIAddGadgetForm> event) throws Exception {
  WebuiRequestContext context=event.getRequestContext();
  UIAddGadgetForm uiForm=event.getSource();
  UIDashboard uiDashboard=uiForm.getAncestorOfType(UIDashboard.class);
  UIDashboardContainer uiContainer=uiDashboard.getChild(UIDashboardContainer.class);
  GadgetRegistryService service=uiForm.getApplicationComponent(GadgetRegistryService.class);
  String url=uiForm.getUIStringInput(FIELD_URL).getValue();
  UIApplication uiApplication=context.getUIApplication();
  if (url == null || url.trim().length() == 0) {
    uiApplication.addMessage(new ApplicationMessage("String_Node_Str",null));
    context.addUIComponentToUpdateByAjax(uiApplication.getUIPopupMessages());
    return;
  }
  try {
    new URL(url);
  }
 catch (  Exception e) {
    uiApplication.addMessage(new ApplicationMessage("String_Node_Str",null));
    context.addUIComponentToUpdateByAjax(uiApplication.getUIPopupMessages());
    return;
  }
  Gadget gadget;
  UIGadget uiGadget;
  try {
    String name="String_Node_Str" + url.hashCode();
    gadget=GadgetUtil.toGadget(name,url,false);
    service.saveGadget(gadget);
    StringBuilder windowId=new StringBuilder(PortalConfig.USER_TYPE);
    windowId.append("String_Node_Str").append(context.getRemoteUser());
    windowId.append("String_Node_Str").append(gadget.getName()).append('/');
    uiGadget=uiForm.createUIComponent(context,UIGadget.class,null,null);
    uiGadget.setId(Integer.toString(uiGadget.hashCode() + 1));
    windowId.append(uiGadget.hashCode());
    uiGadget.setApplicationInstanceId(windowId.toString());
  }
 catch (  Exception e) {
    gadget=service.getGadget("String_Node_Str");
    StringBuilder windowId=new StringBuilder(PortalConfig.USER_TYPE);
    windowId.append("String_Node_Str").append(context.getRemoteUser());
    windowId.append("String_Node_Str").append(gadget.getName()).append('/');
    uiGadget=uiForm.createUIComponent(context,UIGadget.class,null,null);
    uiGadget.setId(Integer.toString(url.hashCode() + 1));
    windowId.append(url.hashCode());
    uiGadget.setApplicationInstanceId(windowId.toString());
    String params="String_Node_Str" + url + "String_Node_Str";
    UserGadgetStorage userGadgetStorage=uiForm.getApplicationComponent(UserGadgetStorage.class);
    userGadgetStorage.save(Util.getPortalRequestContext().getRemoteUser(),gadget.getName(),"String_Node_Str" + url.hashCode(),UIGadget.PREF_KEY,params);
  }
  uiContainer.addUIGadget(uiGadget,0,0);
  uiContainer.save();
  uiForm.reset();
  context.addUIComponentToUpdateByAjax(uiForm);
  context.addUIComponentToUpdateByAjax(uiContainer);
}