You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by Oleg V Alexeev <go...@penza.net> on 2000/09/25 23:44:43 UTC

bug in org.apache.struts.util.PropertyUtils

Hello struts-dev,

May be a bug. For my mind in point 1) there must be return. Because of
that there exception will be thrown after successfully processed
indexed property with index parameter.

Method
> setIndexedProperty(Object, String, int, Object)
in
> org.apache.struts.util.PropertyUtils

    public static void setIndexedProperty(Object bean, String name,
                                          int index, Object value)
        throws IllegalAccessException, InvocationTargetException,
               NoSuchMethodException {

        // Retrieve the property descriptor for the specified property
        PropertyDescriptor descriptor =
            getPropertyDescriptor(bean, name);
        if (descriptor == null)
            throw new NoSuchMethodException("Unknown property '" +
                                            name + "'");

        // Call the indexed setter method if there is one
        if (descriptor instanceof IndexedPropertyDescriptor) {
            Method writeMethod = ((IndexedPropertyDescriptor) descriptor).
                getIndexedWriteMethod();
            if (writeMethod != null) {
                Object subscript[] = new Object[2];
                subscript[0] = new Integer(index);
                subscript[1] = value;
                writeMethod.invoke(bean, subscript);
1) -->          return;
            }
        }

        // Otherwise, the underlying property must be an array
        Method readMethod = descriptor.getReadMethod();
        if (readMethod == null)
            throw new NoSuchMethodException("Property '" + name +
                                            "' has no getter method");

        // Call the property getter to get the array
        Object array = readMethod.invoke(bean, new Object[0]);
        if (!array.getClass().isArray())
            throw new IllegalArgumentException("Property '" + name +
                                               "' is not indexed");

        // Modify the specified value
        Array.set(array, index, value);

    }
  

-- 
Best regards,
 Oleg                          mailto:gonza@penza.net