Program: 73295
Project: 73295
Buggy source:
/** 
 * Load the model from the specified URL.
 * @param modelURL the model URL to be loaded
 * @exception Exception If there is a problem parsing the model,connecting to the mqtt broker or replacing actors.
 */
public void loadModel(URL modelURL) throws Exception {
  MoMLParser parser=_createMoMLParser();
  HashSet<ComponentEntity> unneededActors=new HashSet<ComponentEntity>();
  HashSet<ComponentEntity> sinks=new HashSet<ComponentEntity>();
  HashSet<ComponentEntity> sources=new HashSet<ComponentEntity>();
  setResolvedTypes(new HashMap<String,String>());
  _topLevelActor=(CompositeActor)parser.parse(null,modelURL);
  for (  Object obj : getTopLevelActor().deepEntityList()) {
    ComponentEntity actor=(ComponentEntity)obj;
    Attribute remoteAttribute=actor.getAttribute("String_Node_Str");
    boolean isSinkOrSource=false;
    if (remoteAttribute instanceof Parameter) {
      Parameter parameter=(Parameter)remoteAttribute;
      if (parameter.getExpression().equals("String_Node_Str")) {
        sources.add(actor);
        isSinkOrSource=true;
      }
 else       if (parameter.getExpression().equals("String_Node_Str")) {
        sinks.add(actor);
        isSinkOrSource=true;
      }
    }
    if (!isSinkOrSource && _modelType == RemoteModelType.CLIENT) {
      unneededActors.add(actor);
    }
    _initRemoteAttributes(actor);
  }
  _initRemoteAttributes(_topLevelActor);
  if (_topLevelActor instanceof TypedCompositeActor) {
    TypedCompositeActor typedActor=(TypedCompositeActor)_topLevelActor;
    TypedCompositeActor.resolveTypes(typedActor);
  }
  _captureModelTypes(sources,getResolvedTypes());
  _captureModelTypes(sinks,getResolvedTypes());
switch (_modelType) {
case SERVER:
    for (    ComponentEntity entity : sources) {
      _createSource(entity,true,getResolvedTypes());
    }
  for (  ComponentEntity entity : sinks) {
    _createSink(entity,true,getResolvedTypes());
  }
break;
case CLIENT:
for (ComponentEntity entity : sources) {
_createSink(entity,false,getResolvedTypes());
}
for (ComponentEntity entity : sinks) {
_createSource(entity,false,getResolvedTypes());
}
HashMap<NamedObj,StringAttribute> containerToDummyAttributeMap=new HashMap<NamedObj,StringAttribute>();
for (Settable settable : _settableAttributesMap.values()) {
Attribute attribute=(Attribute)settable;
NamedObj container=attribute.getContainer();
Attribute lastAttribute=attribute;
while (container != _topLevelActor) {
StringAttribute dummyAttribute=containerToDummyAttributeMap.get(container);
if (dummyAttribute == null) {
dummyAttribute=new StringAttribute(container.getContainer(),container.getContainer().uniqueName("String_Node_Str"));
dummyAttribute.setPersistent(true);
containerToDummyAttributeMap.put(container,dummyAttribute);
}
container=container.getContainer();
lastAttribute.setContainer(dummyAttribute);
lastAttribute=dummyAttribute;
}
}
for (ComponentEntity componentEntity : unneededActors) {
componentEntity.setContainer(null);
}
for (Entry<NamedObj,StringAttribute> entry : containerToDummyAttributeMap.entrySet()) {
entry.getValue().setName(entry.getKey().getName());
}
break;
}
}

Fixed version (ground truth):
/** 
 * Load the model from the specified URL.
 * @param modelURL the model URL to be loaded
 * @exception Exception If there is a problem parsing the model,connecting to the mqtt broker or replacing actors.
 */
public void loadModel(URL modelURL) throws Exception {
  MoMLParser parser=_createMoMLParser();
  HashSet<ComponentEntity> unneededActors=new HashSet<ComponentEntity>();
  HashSet<ComponentEntity> sinks=new HashSet<ComponentEntity>();
  HashSet<ComponentEntity> sources=new HashSet<ComponentEntity>();
  _resolvedTypes=new HashMap<String,Type>();
  _topLevelActor=(CompositeActor)parser.parse(null,modelURL);
  for (  Object obj : getTopLevelActor().deepEntityList()) {
    ComponentEntity actor=(ComponentEntity)obj;
    Attribute remoteAttribute=actor.getAttribute("String_Node_Str");
    boolean isSinkOrSource=false;
    if (remoteAttribute instanceof Parameter) {
      Parameter parameter=(Parameter)remoteAttribute;
      if (parameter.getExpression().equals("String_Node_Str")) {
        sources.add(actor);
        isSinkOrSource=true;
      }
 else       if (parameter.getExpression().equals("String_Node_Str")) {
        sinks.add(actor);
        isSinkOrSource=true;
      }
    }
    if (!isSinkOrSource && _modelType == RemoteModelType.CLIENT) {
      unneededActors.add(actor);
    }
    _initRemoteAttributes(actor);
  }
  _initRemoteAttributes(_topLevelActor);
  if (_topLevelActor instanceof TypedCompositeActor) {
    TypedCompositeActor typedActor=(TypedCompositeActor)_topLevelActor;
    TypedCompositeActor.resolveTypes(typedActor);
  }
  _captureModelTypes(sources,getResolvedTypes());
  _captureModelTypes(sinks,getResolvedTypes());
switch (_modelType) {
case SERVER:
    for (    ComponentEntity entity : sources) {
      _createSource(entity,true,getResolvedTypes());
    }
  for (  ComponentEntity entity : sinks) {
    _createSink(entity,true,getResolvedTypes());
  }
break;
case CLIENT:
for (ComponentEntity entity : sources) {
_createSink(entity,false,getResolvedTypes());
}
for (ComponentEntity entity : sinks) {
_createSource(entity,false,getResolvedTypes());
}
HashMap<NamedObj,StringAttribute> containerToDummyAttributeMap=new HashMap<NamedObj,StringAttribute>();
for (Settable settable : _settableAttributesMap.values()) {
Attribute attribute=(Attribute)settable;
NamedObj container=attribute.getContainer();
Attribute lastAttribute=attribute;
while (container != _topLevelActor) {
StringAttribute dummyAttribute=containerToDummyAttributeMap.get(container);
if (dummyAttribute == null) {
dummyAttribute=new StringAttribute(container.getContainer(),container.getContainer().uniqueName("String_Node_Str"));
dummyAttribute.setPersistent(true);
containerToDummyAttributeMap.put(container,dummyAttribute);
}
container=container.getContainer();
lastAttribute.setContainer(dummyAttribute);
lastAttribute=dummyAttribute;
}
}
for (ComponentEntity componentEntity : unneededActors) {
componentEntity.setContainer(null);
}
for (Entry<NamedObj,StringAttribute> entry : containerToDummyAttributeMap.entrySet()) {
entry.getValue().setName(entry.getKey().getName());
}
break;
}
}