Program: 72472
Project: 72472
Buggy source:
/** 
 * Create a new parameter if it does not already exist. The options argument can specify a "type", a "description", and/or a "value". If a type is given, set the type as specified. Otherwise, leave the type unspecified so that it will be inferred from the value. If a description is given, then create, append to, or modify the DocAttribute named "documentation" contained by this actor to include documentation of this output. If a value is given, then set the default value of the parameter if it does not already have a value.
 * @param name The name of the parameter.
 * @param options The options, or null to accept the defaults.
 * @exception IllegalActionException If no name is given.
 * @exception NameDuplicationException If the name is a reserved word, or if an attributealready exists with the name and is not a parameter.
 */
public void parameter(String name,Map options) throws IllegalActionException, NameDuplicationException {
  if (name == null) {
    throw new IllegalActionException(this,"String_Node_Str");
  }
  Attribute parameter=getAttribute(name);
  if (parameter == null) {
    parameter=new Parameter(this,name);
  }
 else {
    if (parameter == script) {
      throw new NameDuplicationException(this,"String_Node_Str" + name);
    }
 else     if (!(parameter instanceof Parameter)) {
      throw new NameDuplicationException(this,"String_Node_Str" + name);
    }
  }
  if (options != null) {
    Type ptType=null;
    Object type=options.get("String_Node_Str");
    if (type instanceof String) {
      ptType=_typeAccessorToPtolemy((String)type,parameter);
    }
 else     if (type != null) {
      throw new IllegalActionException(this,"String_Node_Str" + type);
    }
    if (ptType != null) {
      ((Parameter)parameter).setTypeEquals(ptType);
      _setOptionsForSelect(parameter,options);
    }
    if (((Parameter)parameter).getToken() == null || ((ptType == BaseType.STRING) && parameter instanceof StringParameter && (((StringParameter)parameter).stringValue().equals("String_Node_Str")))) {
      Object value=options.get("String_Node_Str");
      if (value != null) {
        Object token;
        try {
          token=((Invocable)_engine).invokeFunction("String_Node_Str",value);
        }
 catch (        Exception e) {
          throw new IllegalActionException(this,e,"String_Node_Str" + value);
        }
        if (token instanceof Token) {
          ((Parameter)parameter).setToken((Token)token);
        }
 else {
          throw new IllegalActionException(this,"String_Node_Str" + value);
        }
      }
    }
    Object description=options.get("String_Node_Str");
    if (description != null) {
      _setPortDescription(parameter,description.toString());
    }
  }
  if (_proxies.get(parameter) == null) {
    PortOrParameterProxy proxy=new PortOrParameterProxy(parameter);
    _proxies.put(parameter,proxy);
    _proxiesByName.put(parameter.getName(),proxy);
  }
}

Fixed version (ground truth):
/** 
 * Create a new parameter if it does not already exist. The options argument can specify a "type", a "description", and/or a "value". If a type is given, set the type as specified. Otherwise, leave the type unspecified so that it will be inferred from the value. If a description is given, then create, append to, or modify the DocAttribute named "documentation" contained by this actor to include documentation of this output. If a value is given, then set the default value of the parameter if it does not already have a value.
 * @param name The name of the parameter.
 * @param options The options, or null to accept the defaults.
 * @exception IllegalActionException If no name is given.
 * @exception NameDuplicationException If the name is a reserved word, or if an attributealready exists with the name and is not a parameter.
 */
public void parameter(String name,Map options) throws IllegalActionException, NameDuplicationException {
  if (name == null) {
    throw new IllegalActionException(this,"String_Node_Str");
  }
  Attribute parameter=getAttribute(name);
  if (parameter == null) {
    parameter=new Parameter(this,name);
  }
 else {
    if (parameter == script) {
      throw new NameDuplicationException(this,"String_Node_Str" + name);
    }
 else     if (!(parameter instanceof Parameter)) {
      throw new NameDuplicationException(this,"String_Node_Str" + name);
    }
  }
  if (options != null) {
    Type ptType=null;
    Object type=options.get("String_Node_Str");
    if (type instanceof String) {
      ptType=_typeAccessorToPtolemy((String)type,parameter);
    }
 else     if (type != null) {
      throw new IllegalActionException(this,"String_Node_Str" + type);
    }
    if (ptType != null) {
      ((Parameter)parameter).setTypeEquals(ptType);
      _setOptionsForSelect(parameter,options);
    }
    Token previousValue=((Parameter)parameter).getToken();
    if (previousValue == null || ((ptType == BaseType.STRING) && ((Parameter)parameter).isStringMode() && (((StringToken)previousValue).stringValue().equals("String_Node_Str")))) {
      Object value=options.get("String_Node_Str");
      if (value != null) {
        Object token;
        try {
          token=((Invocable)_engine).invokeFunction("String_Node_Str",value);
        }
 catch (        Exception e) {
          throw new IllegalActionException(this,e,"String_Node_Str" + value);
        }
        if (token instanceof Token) {
          ((Parameter)parameter).setToken((Token)token);
        }
 else {
          throw new IllegalActionException(this,"String_Node_Str" + value);
        }
      }
    }
    Object description=options.get("String_Node_Str");
    if (description != null) {
      _setPortDescription(parameter,description.toString());
    }
  }
  if (_proxies.get(parameter) == null) {
    PortOrParameterProxy proxy=new PortOrParameterProxy(parameter);
    _proxies.put(parameter,proxy);
    _proxiesByName.put(parameter.getName(),proxy);
  }
}