Program: 72659
Project: 72659
Buggy source:
/** 
 * Import a FMUFile.
 * @param originator The originator of the change request.
 * @param fmuFileParameter The .fmuFile
 * @param context The context in which the FMU actor is created.
 * @param x The x-axis value of the actor to be created.
 * @param y The y-axis value of the actor to be created.
 * @param modelExchange If true, import for model exchange (vs. co-simulation).
 * @exception IllegalActionException If there is a problem instantiating the actor.
 * @exception IOException If there is a problem parsing the fmu file.
 */
public static void importFMU(Object originator,FileParameter fmuFileParameter,NamedObj context,double x,double y,boolean modelExchange) throws IllegalActionException, IOException {
  File fmuFile=fmuFileParameter.asFile();
  String fmuFileName=fmuFile.getCanonicalPath();
  FMIModelDescription fmiModelDescription=FMUFile.parseFMUFile(fmuFileName);
  String source="String_Node_Str";
  if (fmuFileName.startsWith("String_Node_Str")) {
    source="String_Node_Str" + fmuFileName.trim() + "String_Node_Str";
  }
  String rootName=new File(fmuFileName).getName();
  int index=rootName.lastIndexOf('.');
  if (index != -1) {
    rootName=rootName.substring(0,index);
  }
  int maximumNumberOfPortsToDisplay=20;
  int modelVariablesLength=fmiModelDescription.modelVariables.size();
  String hide="String_Node_Str";
  String hiddenStyle="String_Node_Str";
  String dependency="String_Node_Str";
  String showName="String_Node_Str" + "String_Node_Str" + hiddenStyle + "String_Node_Str";
  if (modelVariablesLength > maximumNumberOfPortsToDisplay) {
    MessageHandler.message("String_Node_Str" + fmuFileName + "String_Node_Str"+ modelVariablesLength+ "String_Node_Str"+ "String_Node_Str");
  }
  int portCount=0;
  StringBuffer parameterMoML=new StringBuffer();
  StringBuffer portMoML=new StringBuffer();
  for (  FMIScalarVariable scalar : fmiModelDescription.modelVariables) {
    if (scalar.variability == FMIScalarVariable.Variability.parameter || scalar.variability == FMIScalarVariable.Variability.fixed) {
switch (scalar.causality) {
case output:
case input:
        portCount++;
      parameterMoML.append("String_Node_Str" + StringUtilities.sanitizeName(scalar.name) + "String_Node_Str"+ scalar.type+ "String_Node_Str");
    break;
case local:
case internal:
case calculatedParameter:
case parameter:
case none:
  parameterMoML.append("String_Node_Str" + StringUtilities.sanitizeName(scalar.name) + "String_Node_Str"+ scalar.type+ "String_Node_Str"+ "String_Node_Str");
break;
}
continue;
}
 else {
boolean hideLocal=false;
String causality="String_Node_Str";
System.out.println("String_Node_Str" + scalar.causality + "String_Node_Str"+ scalar.name);
switch (scalar.causality) {
case local:
hideLocal=true;
if (fmiModelDescription.modelExchange) {
if (fmiModelDescription.continuousStates.contains(scalar.name)) {
System.out.println("String_Node_Str" + scalar.causality + "String_Node_Str"+ scalar.name);
hideLocal=false;
}
portCount++;
dependency="String_Node_Str";
causality="String_Node_Str";
break;
}
case input:
portCount++;
causality="String_Node_Str";
break;
case none:
continue;
case output:
portCount++;
dependency="String_Node_Str";
case internal:
causality="String_Node_Str";
break;
}
portMoML.append("String_Node_Str" + StringUtilities.sanitizeName(scalar.name) + "String_Node_Str"+ "String_Node_Str"+ causality+ "String_Node_Str"+ "String_Node_Str"+ StringUtilities.escapeForXML(scalar.name)+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ _fmiType2PtolemyType(scalar.type)+ "String_Node_Str"+ hiddenStyle+ "String_Node_Str"+ dependency+ showName+ (portCount > maximumNumberOfPortsToDisplay || scalar.causality == Causality.internal || hideLocal ? hide : "String_Node_Str")+ "String_Node_Str");
}
}
if (modelExchange) {
fmiModelDescription.modelExchange=true;
parameterMoML.append("String_Node_Str");
parameterMoML.append("String_Node_Str");
}
String moml="String_Node_Str" + "String_Node_Str" + rootName + "String_Node_Str"+ source+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ x+ "String_Node_Str"+ y+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ fmuFileParameter.getExpression()+ "String_Node_Str"+ "String_Node_Str"+ parameterMoML+ portMoML+ "String_Node_Str";
MoMLChangeRequest request=new MoMLChangeRequest(originator,context,moml);
context.requestChange(request);
}

Fixed version (ground truth):
/** 
 * Import a FMUFile.
 * @param originator The originator of the change request.
 * @param fmuFileParameter The .fmuFile
 * @param context The context in which the FMU actor is created.
 * @param x The x-axis value of the actor to be created.
 * @param y The y-axis value of the actor to be created.
 * @param modelExchange If true, import for model exchange (vs. co-simulation).
 * @exception IllegalActionException If there is a problem instantiating the actor.
 * @exception IOException If there is a problem parsing the fmu file.
 */
public static void importFMU(Object originator,FileParameter fmuFileParameter,NamedObj context,double x,double y,boolean modelExchange) throws IllegalActionException, IOException {
  File fmuFile=fmuFileParameter.asFile();
  String fmuFileName=fmuFile.getCanonicalPath();
  FMIModelDescription fmiModelDescription=FMUFile.parseFMUFile(fmuFileName);
  String source="String_Node_Str";
  if (fmuFileName.startsWith("String_Node_Str")) {
    source="String_Node_Str" + fmuFileName.trim() + "String_Node_Str";
  }
  String rootName=new File(fmuFileName).getName();
  int index=rootName.lastIndexOf('.');
  if (index != -1) {
    rootName=rootName.substring(0,index);
  }
  int maximumNumberOfPortsToDisplay=20;
  int modelVariablesLength=fmiModelDescription.modelVariables.size();
  String hide="String_Node_Str";
  String hiddenStyle="String_Node_Str";
  String dependency="String_Node_Str";
  String showName="String_Node_Str" + "String_Node_Str" + hiddenStyle + "String_Node_Str";
  if (modelVariablesLength > maximumNumberOfPortsToDisplay) {
    MessageHandler.message("String_Node_Str" + fmuFileName + "String_Node_Str"+ modelVariablesLength+ "String_Node_Str"+ "String_Node_Str");
  }
  int portCount=0;
  StringBuffer parameterMoML=new StringBuffer();
  StringBuffer portMoML=new StringBuffer();
  for (  FMIScalarVariable scalar : fmiModelDescription.modelVariables) {
    if (scalar.variability == FMIScalarVariable.Variability.parameter || scalar.variability == FMIScalarVariable.Variability.fixed) {
switch (scalar.causality) {
case output:
case input:
        portCount++;
      parameterMoML.append("String_Node_Str" + StringUtilities.sanitizeName(scalar.name) + "String_Node_Str"+ scalar.type+ "String_Node_Str");
    break;
case local:
case internal:
case calculatedParameter:
case parameter:
case none:
  parameterMoML.append("String_Node_Str" + StringUtilities.sanitizeName(scalar.name) + "String_Node_Str"+ scalar.type+ "String_Node_Str"+ "String_Node_Str");
break;
}
continue;
}
 else {
boolean hideLocal=false;
String causality="String_Node_Str";
System.out.println("String_Node_Str" + scalar.causality + "String_Node_Str"+ scalar.name);
switch (scalar.causality) {
case local:
hideLocal=true;
if (fmiModelDescription.modelExchange) {
if (fmiModelDescription.continuousStates.contains(scalar.name)) {
System.out.println("String_Node_Str" + scalar.causality + "String_Node_Str"+ scalar.name);
hideLocal=false;
}
 else {
if (scalar.type instanceof FMIRealType) {
  if (((FMIRealType)scalar.type).indexState != -1) {
    portCount++;
    dependency="String_Node_Str";
    causality="String_Node_Str";
  }
}
break;
}
}
case input:
portCount++;
causality="String_Node_Str";
break;
case none:
continue;
case output:
portCount++;
dependency="String_Node_Str";
case internal:
causality="String_Node_Str";
break;
}
portMoML.append("String_Node_Str" + StringUtilities.sanitizeName(scalar.name) + "String_Node_Str"+ "String_Node_Str"+ causality+ "String_Node_Str"+ "String_Node_Str"+ StringUtilities.escapeForXML(scalar.name)+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ _fmiType2PtolemyType(scalar.type)+ "String_Node_Str"+ hiddenStyle+ "String_Node_Str"+ dependency+ showName+ (portCount > maximumNumberOfPortsToDisplay || scalar.causality == Causality.internal || hideLocal ? hide : "String_Node_Str")+ "String_Node_Str");
}
}
if (modelExchange) {
fmiModelDescription.modelExchange=true;
parameterMoML.append("String_Node_Str");
parameterMoML.append("String_Node_Str");
}
String moml="String_Node_Str" + "String_Node_Str" + rootName + "String_Node_Str"+ source+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ x+ "String_Node_Str"+ y+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ fmuFileParameter.getExpression()+ "String_Node_Str"+ "String_Node_Str"+ parameterMoML+ portMoML+ "String_Node_Str";
MoMLChangeRequest request=new MoMLChangeRequest(originator,context,moml);
context.requestChange(request);
}