Program: 20601
Project: 20601
Buggy source:
public static void placeResource(Map<String,Resource> resources,Resource createResource){
  String relativeUri=createResource.getRelativeUri();
  Path path=new Path(relativeUri);
  boolean restructure=false;
  for (  String s : new HashSet<String>(resources.keySet())) {
    Path rp=new Path(s);
    if (path.isPrefixOf(rp) && !path.equals(rp)) {
      restructure=true;
      Resource remove=resources.remove(s);
      Path removeFirstSegments=rp.removeFirstSegments(path.segmentCount());
      String portableString="String_Node_Str" + removeFirstSegments.toPortableString();
      portableString=doCleanup(portableString);
      remove.setRelativeUri(portableString);
      Resource old=resources.put(relativeUri,createResource);
      if (old != null) {
        createResource.getActions().putAll(old.getActions());
      }
      Map<String,UriParameter> uriParameters=createResource.getUriParameters();
      Map<String,UriParameter> uriParameters2=remove.getUriParameters();
      for (      String q : uriParameters.keySet()) {
        uriParameters2.remove(q);
      }
      createResource.getResources().put(portableString,remove);
      Resource put=resources.put(relativeUri,createResource);
      if (put != null) {
        createResource.getActions().putAll(put.getActions());
      }
    }
  }
  if (restructure) {
    return;
  }
  for (  String s : resources.keySet()) {
    Path rp=new Path(s);
    if (rp.isPrefixOf(path) && path.segmentCount() - rp.segmentCount() >= 1) {
      Path removeFirstSegments2=path.removeFirstSegments(rp.segmentCount());
      Path removeFirstSegments=removeFirstSegments2;
      String portableString="String_Node_Str" + removeFirstSegments.toPortableString();
      createResource.setRelativeUri(doCleanup(portableString));
      Resource resource=resources.get(s);
      Map<String,UriParameter> uriParameters=resource.getUriParameters();
      Map<String,UriParameter> uriParameters2=createResource.getUriParameters();
      for (      String sa : uriParameters.keySet()) {
        uriParameters2.remove(sa);
      }
      placeResource(resource.getResources(),createResource);
      return;
    }
  }
  Resource put=resources.put(relativeUri,createResource);
  if (put != null) {
    createResource.getActions().putAll(put.getActions());
    createResource.getResources().putAll(put.getResources());
  }
}

Fixed version (ground truth):
public static void placeResource(Map<String,Resource> resources,Resource createResource){
  String relativeUri=createResource.getRelativeUri();
  Path path=new Path(relativeUri);
  boolean restructure=false;
  for (  String s : new HashSet<String>(resources.keySet())) {
    Path rp=new Path(s);
    if (path.isPrefixOf(rp)) {
      if (path.equals(rp)) {
        Resource resource=resources.get(s);
        resource.getActions().putAll(createResource.getActions());
        return;
      }
      restructure=true;
      Resource remove=resources.remove(s);
      Path removeFirstSegments=rp.removeFirstSegments(path.segmentCount());
      String portableString="String_Node_Str" + removeFirstSegments.toPortableString();
      portableString=doCleanup(portableString);
      remove.setRelativeUri(portableString);
      Resource old=resources.put(relativeUri,createResource);
      if (old != null) {
        createResource.getActions().putAll(old.getActions());
      }
      Map<String,UriParameter> uriParameters=createResource.getUriParameters();
      Map<String,UriParameter> uriParameters2=remove.getUriParameters();
      for (      String q : uriParameters.keySet()) {
        uriParameters2.remove(q);
      }
      createResource.getResources().put(portableString,remove);
      Resource put=resources.put(relativeUri,createResource);
      if (put != null) {
        createResource.getActions().putAll(put.getActions());
      }
    }
  }
  if (restructure) {
    return;
  }
  for (  String s : resources.keySet()) {
    Path rp=new Path(s);
    if (rp.isPrefixOf(path) && path.segmentCount() - rp.segmentCount() >= 1) {
      Path removeFirstSegments2=path.removeFirstSegments(rp.segmentCount());
      Path removeFirstSegments=removeFirstSegments2;
      String portableString="String_Node_Str" + removeFirstSegments.toPortableString();
      createResource.setRelativeUri(doCleanup(portableString));
      Resource resource=resources.get(s);
      Map<String,UriParameter> uriParameters=resource.getUriParameters();
      Map<String,UriParameter> uriParameters2=createResource.getUriParameters();
      for (      String sa : uriParameters.keySet()) {
        uriParameters2.remove(sa);
      }
      placeResource(resource.getResources(),createResource);
      return;
    }
  }
  Resource put=resources.put(relativeUri,createResource);
  if (put != null) {
    merge(createResource,put);
  }
}