Program: 146918
Project: 146918
Buggy source:
/** 
 * Makes some (or all) of the table's resources available
 * @param master The global resource to prepare against. Used to establish whether resources need to be fetchedremotely
 * @param instance The instance to prepare against
 * @param toInitialize The ID of a single resource after which the table preparation can stop.
 * @throws UnresolvedResourceException If a resource could not be identified and is required
 * @throws UnfullfilledRequirementsException If some resources are incompatible with the current version of CommCare
 */
public void prepareResources(ResourceTable master,CommCareInstance instance,String toInitialize) throws UnresolvedResourceException, UnfullfilledRequirementsException {
  Vector<Resource> v=GetUnreadyResources();
  int round=-1;
  while (v.size() > 0 || (toInitialize != null && this.getResourceWithId(toInitialize).getStatus() == Resource.RESOURCE_STATUS_UNINITIALIZED)) {
    round++;
    System.out.println("String_Node_Str" + round + "String_Node_Str"+ v.size()+ "String_Node_Str");
    for (    Resource r : v) {
      boolean upgrade=false;
      Vector<Reference> invalid=new Vector<Reference>();
      if (master != null) {
        Resource peer=master.getResourceWithId(r.getResourceId());
        if (peer != null) {
          if (!r.isNewer(peer)) {
            commit(r,Resource.RESOURCE_STATUS_INSTALLED);
            continue;
          }
 else {
            upgrade=true;
          }
          invalid=ResourceTable.explodeLocalReferences(peer,master);
        }
      }
      boolean handled=false;
      for (      ResourceLocation location : r.getLocations()) {
        if (handled) {
          break;
        }
        if (location.isRelative()) {
          for (          Reference ref : explodeReferences(location,r,this,master)) {
            if (location.getAuthority() == Resource.RESOURCE_AUTHORITY_LOCAL && invalid.contains(ref)) {
              System.out.println("String_Node_Str" + location.getLocation());
            }
 else {
              handled=r.getInstaller().install(r,location,ref,this,instance,upgrade);
              if (handled) {
                break;
              }
            }
          }
        }
 else {
          try {
            handled=r.getInstaller().install(r,location,ReferenceManager._().DeriveReference(location.getLocation()),this,instance,upgrade);
            if (handled) {
              break;
            }
          }
 catch (          InvalidReferenceException ire) {
            ire.printStackTrace();
          }
        }
      }
      if (!handled) {
        throw new UnresolvedResourceException(r,"String_Node_Str" + r.getResourceId());
      }
      if (stateListener != null) {
        stateListener.resourceStateUpdated(this);
      }
    }
    v=GetUnreadyResources();
  }
  if (toInitialize != null) {
    return;
  }
  for (  Resource stillPending : GetResources(Resource.RESOURCE_STATUS_PENDING)) {
    this.removeResource(stillPending);
  }
}

Fixed version (ground truth):
/** 
 * Makes some (or all) of the table's resources available
 * @param master The global resource to prepare against. Used to establish whether resources need to be fetchedremotely
 * @param instance The instance to prepare against
 * @param toInitialize The ID of a single resource after which the table preparation can stop.
 * @throws UnresolvedResourceException If a resource could not be identified and is required
 * @throws UnfullfilledRequirementsException If some resources are incompatible with the current version of CommCare
 */
public void prepareResources(ResourceTable master,CommCareInstance instance,String toInitialize) throws UnresolvedResourceException, UnfullfilledRequirementsException {
  Vector<Resource> v=GetUnreadyResources();
  int round=-1;
  while (v.size() > 0 && (toInitialize == null || this.getResourceWithId(toInitialize).getStatus() == Resource.RESOURCE_STATUS_UNINITIALIZED)) {
    round++;
    System.out.println("String_Node_Str" + round + "String_Node_Str"+ v.size()+ "String_Node_Str");
    for (    Resource r : v) {
      boolean upgrade=false;
      Vector<Reference> invalid=new Vector<Reference>();
      if (master != null) {
        Resource peer=master.getResourceWithId(r.getResourceId());
        if (peer != null) {
          if (!r.isNewer(peer)) {
            commit(r,Resource.RESOURCE_STATUS_INSTALLED);
            continue;
          }
 else {
            upgrade=true;
          }
          invalid=ResourceTable.explodeLocalReferences(peer,master);
        }
      }
      boolean handled=false;
      for (      ResourceLocation location : r.getLocations()) {
        if (handled) {
          break;
        }
        if (location.isRelative()) {
          for (          Reference ref : explodeReferences(location,r,this,master)) {
            if (location.getAuthority() == Resource.RESOURCE_AUTHORITY_LOCAL && invalid.contains(ref)) {
              System.out.println("String_Node_Str" + location.getLocation());
            }
 else {
              handled=r.getInstaller().install(r,location,ref,this,instance,upgrade);
              if (handled) {
                break;
              }
            }
          }
        }
 else {
          try {
            handled=r.getInstaller().install(r,location,ReferenceManager._().DeriveReference(location.getLocation()),this,instance,upgrade);
            if (handled) {
              break;
            }
          }
 catch (          InvalidReferenceException ire) {
            ire.printStackTrace();
          }
        }
      }
      if (!handled) {
        throw new UnresolvedResourceException(r,"String_Node_Str" + r.getResourceId());
      }
      if (stateListener != null) {
        stateListener.resourceStateUpdated(this);
      }
    }
    v=GetUnreadyResources();
  }
  if (toInitialize != null) {
    return;
  }
  for (  Resource stillPending : GetResources(Resource.RESOURCE_STATUS_PENDING)) {
    this.removeResource(stillPending);
  }
}