jaxb binding fails for property getters marked @XmlTransient if they return an 
array with component type that is an interface
-----------------------------------------------------------------------------------------------------------------------------

                 Key: CXF-1121
                 URL: https://issues.apache.org/jira/browse/CXF-1121
             Project: CXF
          Issue Type: Bug
            Reporter: Adrian Nistor


I know interfaces (and arrays of interfaces) are not handled by jaxb but these 
properties should at least be ignored if marked @XmlTransient. 
The problem appears for both field and property access mode.
I did some investigation and this is not a jaxb issue, it is certainly caused 
by cxf. 

Found that org.apache.cxf.jaxb.JAXBContextInitializer gathers too many types 
when it visits the service model. In my opinion it should not attempt to add to 
the context ALL the classes it sees in fields and method signatures (see method 
JAXBContextInitializer.walkReferences). It must check if the field or method 
has the @XmlTransient annotation and skip it if so. 

I will attach a patch for JAXBContextInitializer.

Now here is some sample code that triggers the issue. See the exception 
stacktrace below.

public class User {
    ....
    @XmlTransient
    public org.acegisecurity.GrantedAuthority[] getAuthorities() { ... }
    ....
}

------------------------------------------------------------------------------------------------------------------------------------------
ERROR [main] ContextLoader.initWebApplicationContext(203) | Context 
initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean 
with name 'helloWorld': Invocation of init method failed; nested exception is 
org.apache.cxf.service.factory.ServiceConstructionException
Caused by:
org.apache.cxf.service.factory.ServiceConstructionException
        at 
org.apache.cxf.jaxb.JAXBDataBinding.initialize(JAXBDataBinding.java:199)
        at 
org.apache.cxf.service.factory.ReflectionServiceFactoryBean.buildServiceFromClass(ReflectionServiceFactoryBean.java:244)
        at 
org.apache.cxf.service.factory.ReflectionServiceFactoryBean.initializeServiceModel(ReflectionServiceFactoryBean.java:272)
        at 
org.apache.cxf.service.factory.ReflectionServiceFactoryBean.create(ReflectionServiceFactoryBean.java:146)
        at 
org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean.create(JaxWsServiceFactoryBean.java:89)
        at 
org.apache.cxf.frontend.AbstractEndpointFactory.createEndpoint(AbstractEndpointFactory.java:83)
        at 
org.apache.cxf.frontend.ServerFactoryBean.create(ServerFactoryBean.java:107)
        at 
org.apache.cxf.jaxws.JaxWsServerFactoryBean.create(JaxWsServerFactoryBean.java:147)
        at org.apache.cxf.jaxws.EndpointImpl.getServer(EndpointImpl.java:287)
        at org.apache.cxf.jaxws.EndpointImpl.doPublish(EndpointImpl.java:227)
        at org.apache.cxf.jaxws.EndpointImpl.publish(EndpointImpl.java:179)
        at org.apache.cxf.jaxws.EndpointImpl.publish(EndpointImpl.java:340)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at 
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeCustomInitMethod(AbstractAutowireCapableBeanFactory.java:1240)
        at 
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1205)
        at 
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1171)
        at 
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:425)
        at 
org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:251)
        at 
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:156)
        at 
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:248)
        at 
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:160)
        at 
org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:287)
        at 
org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:352)
        at 
org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:244)
        at 
org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:187)
        at 
org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:49)
        at 
org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3764)
        at 
org.apache.catalina.core.StandardContext.start(StandardContext.java:4216)
        at 
org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:760)
        at 
org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:740)
        at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:544)
        at 
org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:920)
        at 
org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:883)
        at 
org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:492)
        at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1138)
        at 
org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)
        at 
org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:120)
        at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1022)
        at org.apache.catalina.core.StandardHost.start(StandardHost.java:736)
        at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1014)
        at 
org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
        at 
org.apache.catalina.core.StandardService.start(StandardService.java:448)
        at 
org.apache.catalina.core.StandardServer.start(StandardServer.java:700)
        at org.apache.catalina.startup.Catalina.start(Catalina.java:552)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:295)
        at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:433)
Caused by: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 1 counts of 
IllegalAnnotationExceptions
org.acegisecurity.GrantedAuthority is an interface, and JAXB can't handle 
interfaces.
        this problem is related to the following location:
                at org.acegisecurity.GrantedAuthority
                at org.acegisecurity.GrantedAuthority[]

        at 
com.sun.xml.bind.v2.runtime.IllegalAnnotationsException$Builder.check(IllegalAnnotationsException.java:66)
        at 
com.sun.xml.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(JAXBContextImpl.java:389)
        at 
com.sun.xml.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:236)
        at 
com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:76)
        at 
com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:55)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:210)
        at javax.xml.bind.ContextFinder.find(ContextFinder.java:366)
        at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:574)
        at 
org.apache.cxf.jaxb.JAXBDataBinding.createJAXBContext(JAXBDataBinding.java:377)
        at 
org.apache.cxf.jaxb.JAXBDataBinding.initialize(JAXBDataBinding.java:182)
        ... 52 more


-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to