Program: 72542
Project: 72542
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 True if the fmu should be importedas a model exchange fmu.
 * @param addMaximumStepSizeParameter True if a parameter named"maximumStepSize" should be added.
 * @param actorClassName The class name of the Ptolemy actorto be instantiated, for example "ptolemy.actor.lib.fmi.FMUImport".
 * @param acceptFMUMethod The {@link #_acceptFMU(FMIModelDescription)}method.  Derived classes provide a different method than the parent class.
 * @exception IllegalActionException If there is a probleminstantiating the actor.
 * @exception IOException If there is a problem parsing the fmu file.
 */
protected static void _importFMU(Object originator,FileParameter fmuFileParameter,NamedObj context,double x,double y,boolean modelExchange,boolean addMaximumStepSizeParameter,String actorClassName,Method acceptFMUMethod) throws IllegalActionException, IOException {
  File fmuFile=fmuFileParameter.asFile();
  String fmuFileName=fmuFile.getCanonicalPath();
  FMIModelDescription fmiModelDescription=FMUFile.parseFMUFile(fmuFileName);
  if (modelExchange) {
    fmiModelDescription.modelExchange=true;
  }
 else {
    fmiModelDescription.modelExchange=false;
  }
  try {
    Boolean accept=(Boolean)acceptFMUMethod.invoke(null,new Object[]{fmiModelDescription});
    if (!accept) {
      return;
    }
  }
 catch (  Throwable throwable) {
    new IllegalActionException(context,throwable,"String_Node_Str" + acceptFMUMethod);
  }
  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 || scalar.variability == FMIScalarVariable.Variability.tunable) {
switch (scalar.causality) {
case output:
        portCount++;
      String causality="String_Node_Str";
    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+ "String_Node_Str");
  break;
case input:
break;
case local:
break;
case internal:
break;
case calculatedParameter:
break;
case parameter:
parameterMoML.append("String_Node_Str" + StringUtilities.sanitizeName(scalar.name) + "String_Node_Str"+ scalar.type+ "String_Node_Str"+ "String_Node_Str");
break;
case none:
break;
}
}
 else if (scalar.variability == FMIScalarVariable.Variability.constant) {
continue;
}
 else {
boolean hideLocal=false;
String causality="String_Node_Str";
switch (scalar.causality) {
case local:
hideLocal=true;
if (fmiModelDescription.modelExchange) {
if (scalar.isState) {
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++;
hideLocal=false;
causality="String_Node_Str";
break;
case none:
hideLocal=true;
causality="String_Node_Str";
break;
case output:
portCount++;
hideLocal=false;
causality="String_Node_Str";
dependency="String_Node_Str";
break;
case internal:
hideLocal=true;
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) {
parameterMoML.append("String_Node_Str");
if (addMaximumStepSizeParameter) {
parameterMoML.append("String_Node_Str");
}
}
String moml="String_Node_Str" + "String_Node_Str" + rootName + "String_Node_Str"+ actorClassName+ "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 True if the fmu should be importedas a model exchange fmu.
 * @param addMaximumStepSizeParameter True if a parameter named"maximumStepSize" should be added.
 * @param actorClassName The class name of the Ptolemy actorto be instantiated, for example "ptolemy.actor.lib.fmi.FMUImport".
 * @param acceptFMUMethod The {@link #_acceptFMU(FMIModelDescription)}method.  Derived classes provide a different method than the parent class.
 * @exception IllegalActionException If there is a probleminstantiating the actor.
 * @exception IOException If there is a problem parsing the fmu file.
 */
protected static void _importFMU(Object originator,FileParameter fmuFileParameter,NamedObj context,double x,double y,boolean modelExchange,boolean addMaximumStepSizeParameter,String actorClassName,Method acceptFMUMethod) throws IllegalActionException, IOException {
  File fmuFile=fmuFileParameter.asFile();
  String fmuFileName=fmuFile.getCanonicalPath();
  FMIModelDescription fmiModelDescription=FMUFile.parseFMUFile(fmuFileName);
  if (modelExchange) {
    fmiModelDescription.modelExchange=true;
  }
 else {
    fmiModelDescription.modelExchange=false;
  }
  try {
    Boolean accept=(Boolean)acceptFMUMethod.invoke(null,new Object[]{fmiModelDescription});
    if (!accept) {
      return;
    }
  }
 catch (  Throwable throwable) {
    if (throwable.getCause() instanceof IOException) {
      throw new IllegalActionException(context,throwable.getCause(),"String_Node_Str" + fmuFile + "String_Node_Str");
    }
 else {
      throw new IllegalActionException(context,throwable,"String_Node_Str" + acceptFMUMethod);
    }
  }
  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 || scalar.variability == FMIScalarVariable.Variability.tunable) {
switch (scalar.causality) {
case output:
        portCount++;
      String causality="String_Node_Str";
    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+ "String_Node_Str");
  break;
case input:
break;
case local:
break;
case internal:
break;
case calculatedParameter:
break;
case parameter:
parameterMoML.append("String_Node_Str" + StringUtilities.sanitizeName(scalar.name) + "String_Node_Str"+ scalar.type+ "String_Node_Str"+ "String_Node_Str");
break;
case none:
break;
}
}
 else if (scalar.variability == FMIScalarVariable.Variability.constant) {
continue;
}
 else {
boolean hideLocal=false;
String causality="String_Node_Str";
switch (scalar.causality) {
case local:
hideLocal=true;
if (fmiModelDescription.modelExchange) {
if (scalar.isState) {
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++;
hideLocal=false;
causality="String_Node_Str";
break;
case none:
hideLocal=true;
causality="String_Node_Str";
break;
case output:
portCount++;
hideLocal=false;
causality="String_Node_Str";
dependency="String_Node_Str";
break;
case internal:
hideLocal=true;
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) {
parameterMoML.append("String_Node_Str");
if (addMaximumStepSizeParameter) {
parameterMoML.append("String_Node_Str");
}
}
String moml="String_Node_Str" + "String_Node_Str" + rootName + "String_Node_Str"+ actorClassName+ "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);
}