Program: 74453
Project: 74453
Buggy source:
/** 
 * Get the NamedObj with the given name in the scope of the given container.  If the name contains the "::" scoping specifier, then an attribute more deeply in the hierarchy is searched for.
 * @param container The container to search upwards from.
 * @param name The object name to search for.
 * @return The NamedObj with the given name or null if the NamedObjdoes not exist.
 */
public static NamedObj getScopedObject(NamedObj container,String name){
  NamedObj reference=container;
  if (name.equals("String_Node_Str")) {
    return reference;
  }
  String[] parts=name.replaceAll("String_Node_Str","String_Node_Str").split("String_Node_Str");
  NamedObj result=null;
  boolean lookup=true;
  for (  String part : parts) {
    result=null;
    while (reference != null) {
      Attribute attribute=reference.getAttribute(part);
      if (attribute != null) {
        result=attribute;
      }
 else {
        if (reference instanceof Entity) {
          Port port=((Entity)reference).getPort(part);
          if (port != null) {
            result=port;
          }
 else           if (reference instanceof CompositeEntity) {
            ComponentEntity entity=((CompositeEntity)reference).getEntity(part);
            if (entity != null) {
              result=entity;
            }
 else {
              ComponentRelation relation=((CompositeEntity)reference).getRelation(part);
              if (relation != null) {
                result=relation;
              }
            }
          }
        }
      }
      if (lookup && result == null) {
        reference=reference.getContainer();
      }
 else {
        break;
      }
    }
    if (result == null) {
      break;
    }
    reference=result;
    lookup=false;
  }
  return result;
}

Fixed version (ground truth):
/** 
 * Get the NamedObj with the given name in the scope of the given container.  If the name contains the "::" scoping specifier, then an attribute more deeply in the hierarchy is searched for.
 * @param container The container to search upwards from.
 * @param name The object name to search for.
 * @return The NamedObj with the given name or null if the NamedObjdoes not exist.
 */
public static NamedObj getScopedObject(NamedObj container,String name){
  if (name.equals("String_Node_Str")) {
    return container;
  }
  String[] parts=name.replaceAll("String_Node_Str","String_Node_Str").split("String_Node_Str");
  NamedObj result=null;
  boolean lookup=true;
  for (  String part : parts) {
    result=null;
    while (container != null) {
      Attribute attribute=container.getAttribute(part);
      if (attribute != null) {
        result=attribute;
      }
 else {
        if (container instanceof Entity) {
          Port port=((Entity)container).getPort(part);
          if (port != null) {
            result=port;
          }
 else           if (container instanceof CompositeEntity) {
            ComponentEntity entity=((CompositeEntity)container).getEntity(part);
            if (entity != null) {
              result=entity;
            }
 else {
              ComponentRelation relation=((CompositeEntity)container).getRelation(part);
              if (relation != null) {
                result=relation;
              }
            }
          }
        }
      }
      if (lookup && result == null) {
        NamedObj containerContainer=container.getContainer();
        if (container instanceof ModalController) {
          try {
            State state=(State)((ModalController)container).getRefinedState();
            if (state == null) {
              container=containerContainer;
            }
 else {
              container=state.getContainer();
            }
          }
 catch (          IllegalActionException e) {
            container=containerContainer;
          }
        }
 else {
          container=containerContainer;
        }
      }
 else {
        break;
      }
    }
    if (result == null) {
      break;
    }
    container=result;
    lookup=false;
  }
  return result;
}