Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
2.2.3
-
None
Description
I have a service interface that returns an object of a class with a (bounded) type parameter. One of the properties of this class is an array of of objects of this type parameter's type.
E.g.
public interface Service {
Result<A> do();
}
public class Result<T extends B> {
private T[] content;
public T[] getContent() {
return content;
}
public void setContent(T[] content) {
this.content = content;
}
}
public class B {}
public class A extends B {}
I get the following exception:
java.lang.ClassCastException: sun.reflect.generics.reflectiveObjects.TypeVariableImpl
at org.apache.cxf.jaxb.JAXBContextInitializer.addType(JAXBContextInitializer.java:185)
at org.apache.cxf.jaxb.JAXBContextInitializer.addType(JAXBContextInitializer.java:170)
at org.apache.cxf.jaxb.JAXBContextInitializer.walkReferences(JAXBContextInitializer.java:281)
at org.apache.cxf.jaxb.JAXBContextInitializer.addClass(JAXBContextInitializer.java:227)
at org.apache.cxf.jaxb.JAXBContextInitializer.begin(JAXBContextInitializer.java:150)
at org.apache.cxf.service.ServiceModelVisitor.visitOperation(ServiceModelVisitor.java:109)
at org.apache.cxf.service.ServiceModelVisitor.visitOperation(ServiceModelVisitor.java:130)
at org.apache.cxf.service.ServiceModelVisitor.walk(ServiceModelVisitor.java:74)
at org.apache.cxf.jaxb.JAXBDataBinding.initialize(JAXBDataBinding.java:322)
at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.buildServiceFromWSDL(ReflectionServiceFactoryBean.java:346)
at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.initializeServiceModel(ReflectionServiceFactoryBean.java:442)
at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.create(ReflectionServiceFactoryBean.java:195)
at org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean.create(JaxWsServiceFactoryBean.java:163)
at org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory.createEndpoint(AbstractWSDLBasedEndpointFactory.java:100)
at org.apache.cxf.frontend.ClientFactoryBean.create(ClientFactoryBean.java:52)
at org.apache.cxf.frontend.ClientProxyFactoryBean.create(ClientProxyFactoryBean.java:102)
at org.apache.cxf.jaxws.JaxWsProxyFactoryBean.create(JaxWsProxyFactoryBean.java:115)
...
I believe the problem is that the JAXBContextInitializer performs a cast without checking whether the array's elements are a class or a type variable. In case of a type variable the bound of the type variable should (of course) be used.