Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
3.1.9
-
Unknown
Description
When resource type is generic and declares more than one type parameter and some of other parameters are used as return type together with collection CXF always returns first resource parameter.
For example resource such this:
interface DocumentResource<ID, T extends Document<ID>> { Set<T> getDocuments(ID id); } class DocumentResourceImpl<String, Document<String>> { Set<Document<String>> getDocument() { // just normal implementation } }
Fails miserably with 3.1.9. Reason why it fails is leaky logic in InjectionUtils:
TypeVariable<?> typeVar = (TypeVariable<?>)((ParameterizedType)type).getActualTypeArguments()[0]; Type theType = InjectionUtils.getSuperType(serviceCls, typeVar); Class<?> cls = theType instanceof Class ? (Class<?>)theType : InjectionUtils.getActualType(theType, 0); type = new ParameterizedCollectionType(cls);
CXF properly discovers type variables but incorrectly assumes that actual collection bound comes as first type parameter. This leads to assumption that return type is Collection<String> instead of Collection<Document<String>>.
Sadly I am not able to patch this code myself because (I think) it requires switching completely to generic type names instead of indexes. This part of code is just getting 4 years old and I believe there is few dead bodies there.
An note here that it used to work with CXF 2.2.7 or some later release thus this seems to be an regression bug.
I checked how jackson classmate handles that and it manages to resolve all type bounds properly.