Program: 3271
Project: 3271
Buggy source:
/** 
 * When DSpace creates Default Group Names they are of a very specific format, for example: <li> COMMUNITY_[ID]_ADMIN <li> COLLECTION_[ID]_ADMIN <li> COLLECTION_[ID]_SUBMIT <li> COLLECTION_[ID]_WORKFLOW_STEP_# <p> Although these names work fine within DSpace, the DSpace internal ID (represented by [ID] above) becomes meaningless when content is exported outside of DSpace.  In order to make these Group names meaningful outside of DSpace, they must be translated into a different format: <li> COMMUNITY_[HANDLE]_ADMIN (e.g. COMMUNITY_hdl:123456789/10_ADMIN), etc. <p> This format replaces the internal ID with an external Handle identifier (which is expected to be more meaningful even when content is exported from DSpace). <p> This method translates between the two Group Name formats. In either case if the specified <code>groupDefaultName</code> looks to be a default group name with an identifier, its identifier is replaced with the value of <code>newGroupIdentifier</code>.  This allows you to more easily translate an internal group name to one that can have meaning external to DSpace (and visa versa). <p> This method may be useful to any Crosswalks/Packagers which deal with import/export of DSpace Groups.
 * @param relatedDso DSpaceObject associated with group
 * @param groupDefaultName Group's default name
 * @return a new default Group name, containing the newGroupIdentifier
 */
public static String crosswalkDefaultGroupName(Context context,String groupDefaultName) throws PackageException {
  if (!groupDefaultName.matches("String_Node_Str")) {
    return groupDefaultName;
  }
  String objType=groupDefaultName.substring(0,groupDefaultName.indexOf("String_Node_Str"));
  String tmpEndString=groupDefaultName.substring(groupDefaultName.indexOf("String_Node_Str") + 1);
  String objID=tmpEndString.substring(0,tmpEndString.indexOf("String_Node_Str"));
  String groupType=tmpEndString.substring(tmpEndString.indexOf("String_Node_Str") + 1);
  try {
    if (objID.contains("String_Node_Str")) {
      DSpaceObject dso=HandleManager.resolveToObject(context,objID.substring(4));
      if (dso == null)       throw new PackageException("String_Node_Str" + objID + "String_Node_Str"+ groupDefaultName+ "String_Node_Str");
      if (Constants.getTypeID(objType) != dso.getType())       throw new PackageException("String_Node_Str" + objID + "String_Node_Str"+ groupDefaultName+ "String_Node_Str");
      return objType + "String_Node_Str" + dso.getID()+ "String_Node_Str"+ groupType;
    }
 else {
      DSpaceObject dso=DSpaceObject.find(context,Constants.getTypeID(objType),Integer.parseInt(objID));
      if (dso == null)       throw new PackageException("String_Node_Str" + objID + "String_Node_Str"+ objType+ "String_Node_Str"+ groupDefaultName+ "String_Node_Str");
      return objType + "String_Node_Str" + "String_Node_Str"+ dso.getHandle()+ "String_Node_Str"+ groupType;
    }
  }
 catch (  SQLException sqle) {
    throw new PackageException("String_Node_Str" + groupDefaultName + "String_Node_Str");
  }
}

Fixed version (ground truth):
/** 
 * When DSpace creates Default Group Names they are of a very specific format, for example: <li> COMMUNITY_[ID]_ADMIN <li> COLLECTION_[ID]_ADMIN <li> COLLECTION_[ID]_SUBMIT <li> COLLECTION_[ID]_WORKFLOW_STEP_# <p> Although these names work fine within DSpace, the DSpace internal ID (represented by [ID] above) becomes meaningless when content is exported outside of DSpace.  In order to make these Group names meaningful outside of DSpace, they must be translated into a different format: <li> COMMUNITY_[HANDLE]_ADMIN (e.g. COMMUNITY_hdl:123456789/10_ADMIN), etc. <p> This format replaces the internal ID with an external Handle identifier (which is expected to be more meaningful even when content is exported from DSpace). <p> This method translates between the two Group Name formats. In either case if the specified <code>groupDefaultName</code> looks to be a default group name with an identifier, its identifier is replaced with the value of <code>newGroupIdentifier</code>.  This allows you to more easily translate an internal group name to one that can have meaning external to DSpace (and visa versa). <p> This method may be useful to any Crosswalks/Packagers which deal with import/export of DSpace Groups.
 * @param relatedDso DSpaceObject associated with group
 * @param groupDefaultName Group's default name
 * @return a new default Group name, containing the newGroupIdentifier
 */
public static String crosswalkDefaultGroupName(Context context,String groupDefaultName) throws PackageException {
  if (!groupDefaultName.matches("String_Node_Str")) {
    return groupDefaultName;
  }
  String objType=groupDefaultName.substring(0,groupDefaultName.indexOf("String_Node_Str"));
  String tmpEndString=groupDefaultName.substring(groupDefaultName.indexOf("String_Node_Str") + 1);
  String objID=tmpEndString.substring(0,tmpEndString.indexOf("String_Node_Str"));
  String groupType=tmpEndString.substring(tmpEndString.indexOf("String_Node_Str") + 1);
  try {
    if (objID.contains("String_Node_Str")) {
      DSpaceObject dso=HandleManager.resolveToObject(context,objID.substring(4));
      if (dso == null) {
        log.warn("String_Node_Str" + groupDefaultName + "String_Node_Str"+ objID+ "String_Node_Str");
        return groupDefaultName;
      }
      if (Constants.getTypeID(objType) != dso.getType())       throw new PackageException("String_Node_Str" + objID + "String_Node_Str"+ groupDefaultName+ "String_Node_Str");
      return objType + "String_Node_Str" + dso.getID()+ "String_Node_Str"+ groupType;
    }
 else {
      DSpaceObject dso=DSpaceObject.find(context,Constants.getTypeID(objType),Integer.parseInt(objID));
      if (dso == null) {
        log.warn("String_Node_Str" + groupDefaultName + "String_Node_Str"+ objID+ "String_Node_Str"+ objType+ "String_Node_Str");
        return groupDefaultName;
      }
      return objType + "String_Node_Str" + "String_Node_Str"+ dso.getHandle()+ "String_Node_Str"+ groupType;
    }
  }
 catch (  SQLException sqle) {
    throw new PackageException("String_Node_Str" + groupDefaultName + "String_Node_Str");
  }
}