private static Object getIndexedValue()

in src/main/java/org/apache/maven/shared/utils/introspection/ReflectionValueExtractor.java [254:295]


    private static Object getIndexedValue(
            final String expression, final int from, final int to, final Object value, final String indexStr)
            throws IntrospectionException {
        try {
            int index = Integer.parseInt(indexStr);

            if (value.getClass().isArray()) {
                return Array.get(value, index);
            }

            if (value instanceof List) {
                ClassMap classMap = getClassMap(value.getClass());
                // use get method on List interface
                Object[] localParams = new Object[] {index};
                Method method = null;
                try {
                    method = classMap.findMethod("get", localParams);
                    return method.invoke(value, localParams);
                } catch (AmbiguousException e) {
                    throw new IntrospectionException(e);
                } catch (IllegalAccessException e) {
                    throw new IntrospectionException(e);
                }
            }
        } catch (NumberFormatException e) {
            return null;
        } catch (InvocationTargetException e) {
            // catch array index issues gracefully, otherwise release
            if (e.getCause() instanceof IndexOutOfBoundsException) {
                return null;
            }

            throw new IntrospectionException(e.getTargetException());
        }

        final String message = String.format(
                "The token '%s' at position '%d' refers to a java.util.List or an array, but the value "
                        + "seems is an instance of '%s'",
                expression.subSequence(from, to), from, value.getClass());

        throw new IntrospectionException(message);
    }