You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Maarten Coene <Ma...@cs.kuleuven.ac.be> on 2002/06/18 14:35:53 UTC

[PATCH] bug in CollectionUtils.index(...)

Hi,

if I pass a Set to the CollectionUtils.index method, this method does 
return the Set instead of the Object located at the i-th position:

Set set = ...
Object firstElement = CollectionUtils.index(set, 0);

This causes for example a ClassCastException in this code:

Subjet user;
Set principals = user.getPrincipals(MyPrincipal.class);
Principal first = (Principal) CollectionUtils.index(principals, 0);

this code throws the following Exception because the index() method returns 
the Set
java.lang.ClassCastException: javax.security.auth.Subject$ClassSet

After taking a look at the CollectionUtils code, I've noticed that not only 
a Set will cause this behaviour, but every Collection that is not a List 
will behave the way described above.

I've included a patch to fix this problem as attachment. I hope someone can 
fix it...

regards,
Maarten

--
Maarten Coene
Katholieke Universiteit Leuven
Dept. Computerwetenschappen             Tel: ++32 (0)16/32 78 25
Celestijnenlaan 200A
B-3001 Heverlee