Program: 146786
Project: 146786
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 {
  Stack<Resource> v=GetUnreadyResources();
  int round=-1;
  while (!v.isEmpty() && (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");
    while (!v.isEmpty()) {
      Resource r=v.pop();
      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;
      UnreliableSourceException theFailure=null;
      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 {
              try {
                handled=installResource(r,location,ref,this,instance,upgrade);
              }
 catch (              UnreliableSourceException use) {
                System.out.println("String_Node_Str");
                theFailure=use;
                handled=false;
                if (use.shouldBreak()) {
                  break;
                }
              }
              if (handled) {
                break;
              }
            }
          }
        }
 else {
          try {
            handled=installResource(r,location,ReferenceManager._().DeriveReference(location.getLocation()),this,instance,upgrade);
            if (handled) {
              break;
            }
          }
 catch (          InvalidReferenceException ire) {
            ire.printStackTrace();
          }
catch (          UnreliableSourceException use) {
            System.out.println("String_Node_Str");
            theFailure=use;
            handled=false;
            if (use.shouldBreak()) {
              break;
            }
          }
        }
      }
      if (!handled) {
        if (theFailure == null) {
          throw new UnresolvedResourceException(r,"String_Node_Str" + r.getResourceId());
        }
 else {
          throw theFailure;
        }
      }
      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 {
  Stack<Resource> v=GetUnreadyResources();
  int round=-1;
  while (!v.isEmpty() && (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");
    while (!v.isEmpty()) {
      Resource r=v.pop();
      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;
      UnreliableSourceException theFailure=null;
      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 {
              try {
                handled=installResource(r,location,ref,this,instance,upgrade);
              }
 catch (              UnreliableSourceException use) {
                theFailure=use;
              }
              if (handled) {
                break;
              }
            }
          }
        }
 else {
          try {
            handled=installResource(r,location,ReferenceManager._().DeriveReference(location.getLocation()),this,instance,upgrade);
            if (handled) {
              break;
            }
          }
 catch (          InvalidReferenceException ire) {
            ire.printStackTrace();
          }
catch (          UnreliableSourceException use) {
            theFailure=use;
          }
        }
      }
      if (!handled) {
        if (theFailure == null) {
          throw new UnresolvedResourceException(r,"String_Node_Str" + r.getResourceId());
        }
 else {
          throw theFailure;
        }
      }
      if (stateListener != null) {
        stateListener.resourceStateUpdated(this);
      }
    }
    v=GetUnreadyResources();
  }
  if (toInitialize != null) {
    return;
  }
  for (  Resource stillPending : GetResources(Resource.RESOURCE_STATUS_PENDING)) {
    this.removeResource(stillPending);
  }
}