Program: 73426
Project: 73426
Buggy source:
/** 
 * Return the value or an expression in the target language for the specified parameter of the associated actor.  If the parameter is specified by an expression, then the expression will be parsed. If any parameter referenced in that expression is specified by another expression, the parsing continues recursively until either a parameter is directly specified by a constant or a parameter can be directly modified during execution in which case a reference to the parameter is generated.
 * @param name The name of the parameter.
 * @param container The container to search upwards from.
 * @return The value or expression as a string.
 * @exception IllegalActionException If the parameter does not exist ordoes not have a value.
 */
final public String getParameterValue(String name,NamedObj container) throws IllegalActionException {
  if (name.contains("String_Node_Str")) {
    name=processCode(name);
  }
  StringTokenizer tokenizer=new StringTokenizer(name,"String_Node_Str");
  String attributeName=tokenizer.nextToken().trim();
  String offset=null;
  String castType=null;
  if (tokenizer.hasMoreTokens()) {
    offset=tokenizer.nextToken().trim();
    if (tokenizer.hasMoreTokens()) {
      CGException.throwException(_component,name + "String_Node_Str" + "String_Node_Str");
    }
  }
  StringTokenizer tokenizer2=new StringTokenizer(attributeName,"String_Node_Str",false);
  if (tokenizer2.countTokens() != 1 && tokenizer2.countTokens() != 2) {
    CGException.throwException(_component,"String_Node_Str" + attributeName);
  }
  if (tokenizer2.countTokens() == 2) {
    castType=tokenizer2.nextToken().trim();
    attributeName=tokenizer2.nextToken().trim();
  }
  Attribute attribute=ModelScope.getScopedVariable(null,container,attributeName);
  if (attribute == null) {
    attribute=container.getAttribute(attributeName);
    if (attribute == null) {
      CGException.throwException(container,"String_Node_Str" + name);
    }
  }
  if (offset == null) {
    if (attribute instanceof Variable) {
      Variable variable=(Variable)attribute;
      ParseTreeCodeGenerator parseTreeCodeGenerator=getParseTreeCodeGenerator();
      if (variable.isStringMode()) {
        return generateTypeConvertMethod("String_Node_Str" + StringUtilities.escapeString(parseTreeCodeGenerator.escapeForTargetLanguage(variable.getExpression())) + "String_Node_Str",castType,"String_Node_Str");
      }
      PtParser parser=new PtParser();
      ASTPtRootNode parseTree=null;
      try {
        parseTree=parser.generateParseTree(variable.getExpression());
      }
 catch (      Throwable throwable) {
        CGException.throwException(variable,throwable,"String_Node_Str" + name + "String_Node_Str"+ container+ "String_Node_Str");
      }
      try {
        parseTreeCodeGenerator.evaluateParseTree(parseTree,new VariableScope(variable));
      }
 catch (      Exception ex) {
        StringBuffer results=new StringBuffer();
        Iterator<?> allScopedVariableNames=ModelScope.getAllScopedVariableNames(variable,container).iterator();
        while (allScopedVariableNames.hasNext()) {
          results.append(allScopedVariableNames.next().toString() + "String_Node_Str");
        }
        CGException.throwException(_component,ex,"String_Node_Str" + variable.getFullName() + "String_Node_Str"+ results.toString());
      }
      String fireCode=processCode(parseTreeCodeGenerator.generateFireCode());
      return generateTypeConvertMethod(fireCode,castType,_getCodeGenerator().codeGenType(variable.getType()));
    }
 else {
      return ((Settable)attribute).getExpression();
    }
  }
 else {
    if (attribute instanceof Parameter) {
      Token token=((Parameter)attribute).getToken();
      if (token instanceof ArrayToken) {
        Token element=((ArrayToken)token).getElement(Integer.valueOf(offset).intValue());
        ParseTreeCodeGenerator parseTreeCodeGenerator=getParseTreeCodeGenerator();
        PtParser parser=new PtParser();
        ASTPtRootNode parseTree=null;
        try {
          parseTree=parser.generateParseTree(element.toString());
        }
 catch (        Throwable throwable) {
          CGException.throwException(attribute,throwable,"String_Node_Str" + name + "String_Node_Str"+ container+ "String_Node_Str");
        }
        parseTreeCodeGenerator.evaluateParseTree(parseTree,new VariableScope((Parameter)attribute));
        String elementCode=processCode(parseTreeCodeGenerator.generateFireCode());
        return generateTypeConvertMethod(elementCode,castType,_getCodeGenerator().codeGenType(element.getType()));
      }
      CGException.throwException(_component,attributeName + "String_Node_Str");
    }
    CGException.throwException(_component,attributeName + "String_Node_Str");
  }
  return "String_Node_Str";
}

Fixed version (ground truth):
/** 
 * Return the value or an expression in the target language for the specified parameter of the associated actor.  If the parameter is specified by an expression, then the expression will be parsed. If any parameter referenced in that expression is specified by another expression, the parsing continues recursively until either a parameter is directly specified by a constant or a parameter can be directly modified during execution in which case a reference to the parameter is generated.
 * @param name The name of the parameter.
 * @param container The container to search upwards from.
 * @return The value or expression as a string.
 * @exception IllegalActionException If the parameter does not exist ordoes not have a value.
 */
final public String getParameterValue(String name,NamedObj container) throws IllegalActionException {
  if (name.contains("String_Node_Str")) {
    name=processCode(name);
  }
  StringTokenizer tokenizer=new StringTokenizer(name,"String_Node_Str");
  String attributeName=tokenizer.nextToken().trim();
  String offset=null;
  String castType=null;
  if (tokenizer.hasMoreTokens()) {
    offset=tokenizer.nextToken().trim();
    if (tokenizer.hasMoreTokens()) {
      CGException.throwException(_component,name + "String_Node_Str" + "String_Node_Str");
    }
  }
  StringTokenizer tokenizer2=new StringTokenizer(attributeName,"String_Node_Str",false);
  if (tokenizer2.countTokens() != 1 && tokenizer2.countTokens() != 2) {
    CGException.throwException(_component,"String_Node_Str" + attributeName);
  }
  if (tokenizer2.countTokens() == 2) {
    castType=tokenizer2.nextToken().trim();
    attributeName=tokenizer2.nextToken().trim();
  }
  Attribute attribute=ModelScope.getScopedVariable(null,container,attributeName);
  if (attribute == null) {
    attribute=container.getAttribute(attributeName);
    if (attribute == null) {
      CGException.throwException(container,"String_Node_Str" + name);
    }
  }
  if (offset == null) {
    if (attribute instanceof Variable) {
      if (attribute instanceof PortParameter) {
        PortParameter portParameter=(PortParameter)attribute;
        TypedIOPort port=portParameter.getPort();
        if (port.isInsideConnected() || port.isOutsideConnected()) {
          String[] portChannel=_parsePortChannel(name);
          String channel=portChannel[1];
          PortCodeGenerator portAdapter=(PortCodeGenerator)_codeGenerator.getAdapter(port);
          return processCode(portAdapter.generateGetCode(channel,"String_Node_Str"));
        }
      }
      Variable variable=(Variable)attribute;
      ParseTreeCodeGenerator parseTreeCodeGenerator=getParseTreeCodeGenerator();
      if (variable.isStringMode()) {
        return generateTypeConvertMethod("String_Node_Str" + StringUtilities.escapeString(parseTreeCodeGenerator.escapeForTargetLanguage(variable.getExpression())) + "String_Node_Str",castType,"String_Node_Str");
      }
      PtParser parser=new PtParser();
      ASTPtRootNode parseTree=null;
      try {
        parseTree=parser.generateParseTree(variable.getExpression());
      }
 catch (      Throwable throwable) {
        CGException.throwException(variable,throwable,"String_Node_Str" + name + "String_Node_Str"+ container+ "String_Node_Str");
      }
      try {
        parseTreeCodeGenerator.evaluateParseTree(parseTree,new VariableScope(variable));
      }
 catch (      Exception ex) {
        StringBuffer results=new StringBuffer();
        Iterator<?> allScopedVariableNames=ModelScope.getAllScopedVariableNames(variable,container).iterator();
        while (allScopedVariableNames.hasNext()) {
          results.append(allScopedVariableNames.next().toString() + "String_Node_Str");
        }
        CGException.throwException(_component,ex,"String_Node_Str" + variable.getFullName() + "String_Node_Str"+ results.toString());
      }
      String fireCode=processCode(parseTreeCodeGenerator.generateFireCode());
      return generateTypeConvertMethod(fireCode,castType,_getCodeGenerator().codeGenType(variable.getType()));
    }
 else {
      return ((Settable)attribute).getExpression();
    }
  }
 else {
    if (attribute instanceof Parameter) {
      Token token=((Parameter)attribute).getToken();
      if (token instanceof ArrayToken) {
        Token element=((ArrayToken)token).getElement(Integer.valueOf(offset).intValue());
        ParseTreeCodeGenerator parseTreeCodeGenerator=getParseTreeCodeGenerator();
        PtParser parser=new PtParser();
        ASTPtRootNode parseTree=null;
        try {
          parseTree=parser.generateParseTree(element.toString());
        }
 catch (        Throwable throwable) {
          CGException.throwException(attribute,throwable,"String_Node_Str" + name + "String_Node_Str"+ container+ "String_Node_Str");
        }
        parseTreeCodeGenerator.evaluateParseTree(parseTree,new VariableScope((Parameter)attribute));
        String elementCode=processCode(parseTreeCodeGenerator.generateFireCode());
        return generateTypeConvertMethod(elementCode,castType,_getCodeGenerator().codeGenType(element.getType()));
      }
      CGException.throwException(_component,attributeName + "String_Node_Str");
    }
    CGException.throwException(_component,attributeName + "String_Node_Str");
  }
  return "String_Node_Str";
}