Program: 74459
Project: 74459
Buggy source:
/** 
 * Invoke a method of the class for the given object, or retrieve a field of it.
 */
private ptolemy.data.Token _invokeMethod(Class<?> clazz,Object object,String methodName,Type[] argTypes,Object[] argValues) throws IllegalActionException {
  Object result=null;
  if (argTypes.length == 1) {
    Field[] fields=clazz.getFields();
    for (    Field field : fields) {
      if (field.getName().equals(methodName) && Modifier.isPublic(field.getModifiers())) {
        try {
          result=field.get(object);
        }
 catch (        IllegalArgumentException e) {
        }
catch (        IllegalAccessException e) {
        }
      }
    }
  }
  Method[] methods=clazz.getMethods();
  int argCount=argTypes.length - 1;
  Object[] args=new Object[argCount];
  for (  Method method : methods) {
    if (method.getName().equals(methodName) && Modifier.isPublic(method.getModifiers())) {
      Class<?>[] parameterTypes=method.getParameterTypes();
      if (parameterTypes.length != argCount) {
        continue;
      }
      boolean compatible=true;
      for (int i=0; compatible && i < argCount; i++) {
        Class<?> argumentType=ConversionUtilities.convertTokenTypeToJavaType(argTypes[i + 1]);
        if (!parameterTypes[i].isAssignableFrom(argumentType)) {
          compatible=false;
        }
 else {
          Object argument=argValues[i + 1];
          if (argument instanceof ObjectToken) {
            args[i]=((ObjectToken)argument).getValue();
          }
 else           if (argument instanceof ptolemy.data.Token) {
            args[i]=ConversionUtilities.convertTokenToJavaType((ptolemy.data.Token)argument);
          }
 else {
            args[i]=argument;
          }
        }
      }
      if (compatible) {
        try {
          result=method.invoke(object,args);
          break;
        }
 catch (        IllegalArgumentException e) {
        }
catch (        IllegalAccessException e) {
        }
catch (        InvocationTargetException e) {
        }
      }
    }
  }
  if (result == null) {
    return null;
  }
 else {
    if (result instanceof Variable) {
      return ((Variable)result).getToken();
    }
 else {
      return ConversionUtilities.convertJavaTypeToToken(result);
    }
  }
}

Fixed version (ground truth):
/** 
 * Invoke a method of the class for the given object, or retrieve a field of it.
 */
private ptolemy.data.Token _invokeMethod(Class<?> clazz,Object object,String methodName,Type[] argTypes,Object[] argValues) throws IllegalActionException {
  Object result=null;
  if (argTypes.length == 1) {
    Field[] fields=clazz.getFields();
    for (    Field field : fields) {
      if (field.getName().equals(methodName) && Modifier.isPublic(field.getModifiers())) {
        try {
          result=field.get(object);
        }
 catch (        IllegalArgumentException e) {
        }
catch (        IllegalAccessException e) {
        }
      }
    }
  }
  Method[] methods=clazz.getMethods();
  int argCount=argTypes.length - 1;
  Object[] args=new Object[argCount];
  for (  Method method : methods) {
    if (method.getName().equals(methodName) && Modifier.isPublic(method.getModifiers())) {
      Class<?>[] parameterTypes=method.getParameterTypes();
      if (parameterTypes.length != argCount) {
        continue;
      }
      boolean compatible=true;
      for (int i=0; compatible && i < argCount; i++) {
        Class<?> argumentType=ConversionUtilities.convertTokenTypeToJavaType(argTypes[i + 1]);
        if (!parameterTypes[i].isAssignableFrom(argumentType)) {
          compatible=false;
        }
 else {
          Object argument=argValues[i + 1];
          if (argument instanceof ObjectToken) {
            args[i]=((ObjectToken)argument).getValue();
          }
 else           if (argument instanceof ptolemy.data.Token) {
            args[i]=ConversionUtilities.convertTokenToJavaType((ptolemy.data.Token)argument);
          }
 else {
            args[i]=argument;
          }
        }
      }
      if (compatible) {
        try {
          result=method.invoke(object,args);
          if (result == null) {
            result=new ObjectToken(null,method.getReturnType());
          }
          break;
        }
 catch (        IllegalArgumentException e) {
        }
catch (        IllegalAccessException e) {
        }
catch (        InvocationTargetException e) {
        }
      }
    }
  }
  if (result == null) {
    return null;
  }
 else {
    return ConversionUtilities.convertJavaTypeToToken(result);
  }
}