Program: 72327
Project: 72327
Buggy source:
/** 
 * Evaluate the specified method.  The object on which the method is evaluated should be the first argument.
 * @param methodName The method name.
 * @param argTypes An array of argument types.
 * @param argValues An array of argument values.
 * @return The value of returned by the specified method.
 * @exception IllegalActionException If an evaluation error occurs.
 */
protected ptolemy.data.Token _methodCall(String methodName,Type[] argTypes,Object[] argValues) throws IllegalActionException {
  CachedMethod method=CachedMethod.findMethod(methodName,argTypes,CachedMethod.METHOD);
  if (method.isValid()) {
    if (_trace != null) {
      _trace("String_Node_Str" + method.methodDescription());
      _trace("String_Node_Str" + method);
    }
    ptolemy.data.Token result=method.invoke(argValues);
    return result;
  }
  if (argValues[0] instanceof ObjectToken) {
    ObjectToken objectToken=(ObjectToken)argValues[0];
    Object object=objectToken.getValue();
    if (object != null) {
      if (object instanceof NamedObj) {
        Object result=((NamedObj)object).getAttribute(methodName);
        if (result == null && object instanceof Entity) {
          result=((Entity)object).getPort(methodName);
        }
        if (result == null && object instanceof CompositeEntity) {
          result=((CompositeEntity)object).getEntity(methodName);
          if (result == null) {
            result=((CompositeEntity)object).getRelation(methodName);
          }
        }
        if (result == null) {
          List attributes=((NamedObj)object).attributeList(ContainmentExtender.class);
          Iterator attrIterator=attributes.iterator();
          while (result == null && attrIterator.hasNext()) {
            ContainmentExtender extender=(ContainmentExtender)attrIterator.next();
            result=extender.getContainedObject(methodName);
          }
        }
        if (result != null) {
          if (result instanceof Variable) {
            return ((Variable)result).getToken();
          }
 else {
            return new ObjectToken(result,result.getClass());
          }
        }
      }
    }
    Class<?> valueClass=object == null ? objectToken.getValueClass() : object.getClass();
    Set<Class<?>> classes=new HashSet<Class<?>>();
    classes.add(valueClass);
    while (!classes.isEmpty()) {
      Iterator<Class<?>> iterator=classes.iterator();
      valueClass=iterator.next();
      iterator.remove();
      if (!Modifier.isPublic(valueClass.getModifiers())) {
        for (        Class<?> interf : valueClass.getInterfaces()) {
          classes.add(interf);
        }
        Class<?> superclass=valueClass.getSuperclass();
        if (superclass != null) {
          classes.add(superclass);
        }
      }
 else {
        ptolemy.data.Token result=_invokeMethod(valueClass,object,methodName,argTypes,argValues);
        if (result != null) {
          return result;
        }
      }
    }
    if (object == null) {
      throw new IllegalActionException("String_Node_Str" + "String_Node_Str" + methodName + "String_Node_Str"+ "String_Node_Str");
    }
  }
  throw new IllegalActionException("String_Node_Str" + method.toString());
}

Fixed version (ground truth):
/** 
 * Evaluate the specified method.  The object on which the method is evaluated should be the first argument.
 * @param methodName The method name.
 * @param argTypes An array of argument types.
 * @param argValues An array of argument values.
 * @return The value of returned by the specified method.
 * @exception IllegalActionException If an evaluation error occurs.
 */
protected ptolemy.data.Token _methodCall(String methodName,Type[] argTypes,Object[] argValues) throws IllegalActionException {
  CachedMethod method=CachedMethod.findMethod(methodName,argTypes,CachedMethod.METHOD);
  if (method.isValid()) {
    if (_trace != null) {
      _trace("String_Node_Str" + method.methodDescription());
      _trace("String_Node_Str" + method);
    }
    ptolemy.data.Token result=method.invoke(argValues);
    return result;
  }
  if (argValues[0] instanceof ObjectToken) {
    ObjectToken objectToken=(ObjectToken)argValues[0];
    Object object=objectToken.getValue();
    if (object != null) {
      if (object instanceof NamedObj) {
        Object result=((NamedObj)object).getAttribute(methodName);
        if (result == null && object instanceof Entity) {
          result=((Entity)object).getPort(methodName);
        }
        if (result == null && object instanceof CompositeEntity) {
          result=((CompositeEntity)object).getEntity(methodName);
          if (result == null) {
            result=((CompositeEntity)object).getRelation(methodName);
          }
        }
        if (result == null) {
          List attributes=((NamedObj)object).attributeList(ContainmentExtender.class);
          Iterator attrIterator=attributes.iterator();
          while (result == null && attrIterator.hasNext()) {
            ContainmentExtender extender=(ContainmentExtender)attrIterator.next();
            result=extender.getContainedObject(methodName);
          }
        }
        if (result != null) {
          if (result instanceof Variable) {
            ptolemy.data.Token token=((Variable)result).getToken();
            if (token instanceof MatrixToken) {
              if (argValues.length < 2 || !(argValues[1] instanceof IntToken)) {
                return token;
              }
              int row=((IntToken)(argValues[1])).intValue();
              int column=0;
              if (argValues.length >= 3 && !(argValues[2] instanceof IntToken)) {
                column=((IntToken)(argValues[2])).intValue();
              }
              return ((MatrixToken)token).getElementAsToken(row,column);
            }
            if (token instanceof ArrayToken) {
              if (argValues.length < 2 || !(argValues[1] instanceof IntToken)) {
                return token;
              }
              int index=((IntToken)(argValues[1])).intValue();
              return ((ArrayToken)token).getElement(index);
            }
            return token;
          }
 else {
            return new ObjectToken(result,result.getClass());
          }
        }
      }
    }
    Class<?> valueClass=object == null ? objectToken.getValueClass() : object.getClass();
    Set<Class<?>> classes=new HashSet<Class<?>>();
    classes.add(valueClass);
    while (!classes.isEmpty()) {
      Iterator<Class<?>> iterator=classes.iterator();
      valueClass=iterator.next();
      iterator.remove();
      if (!Modifier.isPublic(valueClass.getModifiers())) {
        for (        Class<?> interf : valueClass.getInterfaces()) {
          classes.add(interf);
        }
        Class<?> superclass=valueClass.getSuperclass();
        if (superclass != null) {
          classes.add(superclass);
        }
      }
 else {
        ptolemy.data.Token result=_invokeMethod(valueClass,object,methodName,argTypes,argValues);
        if (result != null) {
          return result;
        }
      }
    }
    if (object == null) {
      throw new IllegalActionException("String_Node_Str" + "String_Node_Str" + methodName + "String_Node_Str"+ "String_Node_Str");
    }
  }
  throw new IllegalActionException("String_Node_Str" + method.toString());
}