And I am the one to question those assumptions :)

There is code which tests for the type of the container

            else if (Introspector.implementsMethod(listObject, "iterator"))
                type = INFO_ITERATOR;
            else if (Introspector.implementsMethod(listObject, "values"))
                type = INFO_MAP;

and then code which uses this information to make type casts

        case INFO_ITERATOR :
            if (((Collection) listObject).size() == 0)
                return null;    
            return ((Collection) listObject).iterator();        
...
        case INFO_MAP:          
            if (((Map) listObject).size() == 0)
                return null;
            return ((Map) listObject).values().iterator();

The problem is that the tests don't guarantee the type of listObject and
so these casts may throw.

Is there some reason why the test section doesn't look like the following?

            else if ( listObject instanceof Collection )
                type = INFO_ITERATOR;
            else if ( listObject instanceof Map )
                type = INFO_MAP;

Reply via email to