Program: 88631
Project: 88631
Buggy source:
public static Map<String,Object> importHierarchy(Element document,JSONObject md,JSONObject keyed) throws ReadOnlyElementException {
  Project project=Application.getInstance().getProject();
  Map<String,Object> retval=new HashMap<String,Object>();
  retval.put("String_Node_Str",true);
  ElementsFactory ef=Application.getInstance().getProject().getElementsFactory();
  Stereotype viewS=Utils.getViewClassStereotype();
  Map<String,List<Property>> viewId2props=new HashMap<String,List<Property>>();
  Set<String> processedViews=new HashSet<String>();
  List<JSONObject> newviews=new ArrayList<JSONObject>();
  for (  Object vid : md.keySet()) {
    String viewid=(String)vid;
    Element view=ExportUtility.getElementFromID(viewid);
    if (view != null && view instanceof Class) {
      if (!view.isEditable() && !ProjectUtilities.isElementInAttachedProject(view))       TeamworkUtils.lockElement(project,view,false);
      for (      Property p : ((Class)view).getOwnedAttribute()) {
        Type t=p.getType();
        if (t != null && StereotypesHelper.hasStereotypeOrDerived(t,viewS)) {
          List<Property> viewprops=viewId2props.get(t.getID());
          if (viewprops == null) {
            viewprops=new ArrayList<Property>();
            viewId2props.put(t.getID(),viewprops);
          }
          viewprops.add(p);
        }
      }
      processedViews.add(view.getID());
    }
  }
  for (  Object vid : keyed.keySet()) {
    String viewid=(String)vid;
    if (processedViews.contains(viewid))     continue;
    Element view=ExportUtility.getElementFromID(viewid);
    if (view != null && view instanceof Class) {
      if (!view.isEditable() && !ProjectUtilities.isElementInAttachedProject(view))       TeamworkUtils.lockElement(project,view,false);
      for (      Property p : ((Class)view).getOwnedAttribute()) {
        Type t=p.getType();
        if (t != null && StereotypesHelper.hasStereotypeOrDerived(t,viewS)) {
          List<Property> viewprops=viewId2props.get(t.getID());
          if (viewprops == null) {
            viewprops=new ArrayList<Property>();
            viewId2props.put(t.getID(),viewprops);
          }
          viewprops.add(p);
        }
      }
    }
 else {
      String url=ExportUtility.getUrlWithWorkspace();
      url+="String_Node_Str" + viewid;
      String result=ExportUtility.get(url,false);
      if (result != null) {
        JSONObject ob=(JSONObject)JSONValue.parse(result);
        if (ob != null) {
          JSONArray elements=(JSONArray)ob.get("String_Node_Str");
          if (elements != null && !elements.isEmpty()) {
            JSONObject viewob=(JSONObject)elements.get(0);
            newviews.add(viewob);
          }
        }
      }
    }
  }
  List<JSONObject> sortedNewviews=ImportUtility.getCreationOrder(newviews);
  if (sortedNewviews == null) {
    Application.getInstance().getGUILog().log("String_Node_Str");
    retval.put("String_Node_Str",false);
    return retval;
  }
  for (  JSONObject ob : sortedNewviews) {
    Element newview=ImportUtility.createElement(ob,true);
    if (newview != null) {
      List<Property> viewprops=new ArrayList<Property>();
      viewId2props.put(newview.getID(),viewprops);
    }
 else {
      Application.getInstance().getGUILog().log("String_Node_Str");
      retval.put("String_Node_Str",false);
      return retval;
    }
  }
  Set<Property> moved=new HashSet<Property>();
  Set<Element> added=new HashSet<Element>();
  Set<Element> deleted=new HashSet<Element>();
  Set<Property> ptyped=new HashSet<Property>();
  for (  Object vid : keyed.keySet()) {
    String viewid=(String)vid;
    JSONArray children=(JSONArray)keyed.get(vid);
    List<Property> cprops=new ArrayList<Property>();
    Element view=ExportUtility.getElementFromID(viewid);
    if (view != null && view instanceof Class) {
      for (      Object cid : children) {
        String childId=(String)cid;
        List<Property> availableProps=viewId2props.get(childId);
        if (availableProps == null || availableProps.isEmpty()) {
          Element cview=ExportUtility.getElementFromID(childId);
          if (cview instanceof Type) {
            Association association=ef.createAssociationInstance();
            Property propType1=ModelHelper.getFirstMemberEnd(association);
            propType1.setName(((NamedElement)cview).getName().toLowerCase());
            propType1.setAggregation(AggregationKindEnum.COMPOSITE);
            propType1.setType((Type)cview);
            ModelHelper.setNavigable(propType1,true);
            Stereotype partPropertyST=Utils.getStereotype("String_Node_Str");
            StereotypesHelper.addStereotype(propType1,partPropertyST);
            Property propType2=ModelHelper.getSecondMemberEnd(association);
            propType2.setType((Type)view);
            propType2.setOwner(association);
            association.setOwner(document.getOwner());
            cprops.add(propType1);
            added.add(propType1);
            added.add(propType2);
            added.add(association);
          }
        }
 else {
          Property p=availableProps.remove(0);
          if (p.getOwner() != view) {
            moved.add(p);
            Property opposite=getOpposite(p);
            if (opposite != null) {
              opposite.setType((Type)view);
              JSONObject ptype=new JSONObject();
              ptype.put("String_Node_Str",opposite.getID());
              JSONObject spec=new JSONObject();
              spec.put("String_Node_Str","String_Node_Str");
              spec.put("String_Node_Str",view.getID());
              ptype.put("String_Node_Str",spec);
              ptyped.add(opposite);
            }
          }
          cprops.add(p);
        }
      }
      for (      Property p : ((Class)view).getOwnedAttribute()) {
        if (p.getType() == null || !StereotypesHelper.hasStereotypeOrDerived(p.getType(),viewS)) {
          cprops.add(p);
        }
      }
      ((Class)view).getOwnedAttribute().clear();
      ((Class)view).getOwnedAttribute().addAll(cprops);
    }
  }
  for (  List<Property> props : viewId2props.values()) {
    for (    Property p : props) {
      deleted.add(p);
      Association asso=p.get_associationOfNavigableOwnedEnd();
      if (asso != null) {
        deleted.addAll(asso.getOwnedEnd());
        deleted.add(asso);
      }
      ModelElementsManager.getInstance().removeElement(p);
    }
  }
  Set<String> deletedIds=new HashSet<String>();
  for (  Element deletedE : deleted) {
    deletedIds.add(deletedE.getID());
  }
  retval.put("String_Node_Str",deleted);
  retval.put("String_Node_Str",deletedIds);
  retval.put("String_Node_Str",added);
  retval.put("String_Node_Str",moved);
  retval.put("String_Node_Str",ptyped);
  return retval;
}

Fixed version (ground truth):
public static Map<String,Object> importHierarchy(Element document,JSONObject md,JSONObject keyed) throws ReadOnlyElementException {
  Project project=Application.getInstance().getProject();
  Map<String,Object> retval=new HashMap<String,Object>();
  retval.put("String_Node_Str",true);
  ElementsFactory ef=Application.getInstance().getProject().getElementsFactory();
  Stereotype viewS=Utils.getViewClassStereotype();
  Map<String,List<Property>> viewId2props=new HashMap<String,List<Property>>();
  Set<String> processedViews=new HashSet<String>();
  List<JSONObject> newviews=new ArrayList<JSONObject>();
  for (  Object vid : md.keySet()) {
    String viewid=(String)vid;
    Element view=ExportUtility.getElementFromID(viewid);
    if (view != null && view instanceof Class) {
      if (!view.isEditable() && !ProjectUtilities.isElementInAttachedProject(view))       TeamworkUtils.lockElement(project,view,false);
      for (      Property p : ((Class)view).getOwnedAttribute()) {
        Type t=p.getType();
        if (t != null && StereotypesHelper.hasStereotypeOrDerived(t,viewS)) {
          List<Property> viewprops=viewId2props.get(t.getID());
          if (viewprops == null) {
            viewprops=new ArrayList<Property>();
            viewId2props.put(t.getID(),viewprops);
          }
          viewprops.add(p);
        }
      }
      processedViews.add(view.getID());
    }
  }
  for (  Object vid : keyed.keySet()) {
    String viewid=(String)vid;
    if (processedViews.contains(viewid))     continue;
    Element view=ExportUtility.getElementFromID(viewid);
    if (view != null && view instanceof Class) {
      if (!view.isEditable() && !ProjectUtilities.isElementInAttachedProject(view))       TeamworkUtils.lockElement(project,view,false);
      for (      Property p : ((Class)view).getOwnedAttribute()) {
        Type t=p.getType();
        if (t != null && StereotypesHelper.hasStereotypeOrDerived(t,viewS)) {
          List<Property> viewprops=viewId2props.get(t.getID());
          if (viewprops == null) {
            viewprops=new ArrayList<Property>();
            viewId2props.put(t.getID(),viewprops);
          }
          viewprops.add(p);
        }
      }
    }
 else {
      String url=ExportUtility.getUrlWithWorkspace();
      url+="String_Node_Str" + viewid;
      String result=ExportUtility.get(url,false);
      if (result != null) {
        JSONObject ob=(JSONObject)JSONValue.parse(result);
        if (ob != null) {
          JSONArray elements=(JSONArray)ob.get("String_Node_Str");
          if (elements != null && !elements.isEmpty()) {
            JSONObject viewob=(JSONObject)elements.get(0);
            newviews.add(viewob);
          }
        }
      }
    }
  }
  List<JSONObject> sortedNewviews=ImportUtility.getCreationOrder(newviews);
  if (sortedNewviews == null) {
    Application.getInstance().getGUILog().log("String_Node_Str");
    retval.put("String_Node_Str",false);
    return retval;
  }
  for (  JSONObject ob : sortedNewviews) {
    Element newview=ImportUtility.createElement(ob,true);
    if (newview != null) {
      List<Property> viewprops=new ArrayList<Property>();
      viewId2props.put(newview.getID(),viewprops);
    }
 else {
      Application.getInstance().getGUILog().log("String_Node_Str");
      retval.put("String_Node_Str",false);
      return retval;
    }
  }
  Set<Property> moved=new HashSet<Property>();
  Set<Element> added=new HashSet<Element>();
  Set<Element> deleted=new HashSet<Element>();
  Set<Property> ptyped=new HashSet<Property>();
  for (  Object vid : keyed.keySet()) {
    String viewid=(String)vid;
    JSONArray children=(JSONArray)keyed.get(vid);
    List<Property> cprops=new ArrayList<Property>();
    Element view=ExportUtility.getElementFromID(viewid);
    if (view != null && view instanceof Class) {
      for (      Object cid : children) {
        String childId=(String)cid;
        List<Property> availableProps=viewId2props.get(childId);
        if (availableProps == null || availableProps.isEmpty()) {
          Element cview=ExportUtility.getElementFromID(childId);
          if (cview instanceof Type) {
            Association association=ef.createAssociationInstance();
            Property propType1=ModelHelper.getFirstMemberEnd(association);
            propType1.setName(((NamedElement)cview).getName().toLowerCase());
            propType1.setAggregation(AggregationKindEnum.COMPOSITE);
            propType1.setType((Type)cview);
            ModelHelper.setNavigable(propType1,true);
            Stereotype partPropertyST=Utils.getStereotype("String_Node_Str");
            StereotypesHelper.addStereotype(propType1,partPropertyST);
            Property propType2=ModelHelper.getSecondMemberEnd(association);
            propType2.setType((Type)view);
            propType2.setOwner(association);
            association.setOwner(document.getOwner());
            cprops.add(propType1);
            added.add(propType1);
            added.add(propType2);
            added.add(association);
          }
        }
 else {
          Property p=availableProps.remove(0);
          if (p.getOwner() != view) {
            moved.add(p);
            Property opposite=getOpposite(p);
            if (opposite != null) {
              opposite.setType((Type)view);
              JSONObject ptype=new JSONObject();
              ptype.put("String_Node_Str",opposite.getID());
              JSONObject spec=new JSONObject();
              spec.put("String_Node_Str","String_Node_Str");
              spec.put("String_Node_Str",view.getID());
              ptype.put("String_Node_Str",spec);
              ptyped.add(opposite);
            }
          }
          cprops.add(p);
        }
      }
      for (      Property p : ((Class)view).getOwnedAttribute()) {
        if (p.getType() == null || !StereotypesHelper.hasStereotypeOrDerived(p.getType(),viewS)) {
          cprops.add(p);
        }
      }
      ((Class)view).getOwnedAttribute().clear();
      ((Class)view).getOwnedAttribute().addAll(cprops);
    }
  }
  for (  List<Property> props : viewId2props.values()) {
    for (    Property p : props) {
      deleted.add(p);
      Association asso=p.getAssociation();
      if (asso != null) {
        deleted.addAll(asso.getOwnedEnd());
        deleted.add(asso);
      }
      ModelElementsManager.getInstance().removeElement(p);
    }
  }
  Set<String> deletedIds=new HashSet<String>();
  for (  Element deletedE : deleted) {
    deletedIds.add(deletedE.getID());
  }
  retval.put("String_Node_Str",deleted);
  retval.put("String_Node_Str",deletedIds);
  retval.put("String_Node_Str",added);
  retval.put("String_Node_Str",moved);
  retval.put("String_Node_Str",ptyped);
  return retval;
}