cxf-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Carlos Marin (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (CXF-3470) WildcardTypeImpl cannot be cast to java.lang.Class - Class Cast exception thrown after upgrading from 2.2.3 to 2.4.0
Date Mon, 25 Apr 2011 19:55:03 GMT

    [ https://issues.apache.org/jira/browse/CXF-3470?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13024931#comment-13024931
] 

Carlos Marin commented on CXF-3470:
-----------------------------------

Please consider the following to fix:

Index: src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
===================================================================
--- src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java	(revision 1095513)
+++ src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java	(working copy)
@@ -30,6 +30,7 @@
 import java.lang.reflect.Proxy;
 import java.lang.reflect.Type;
 import java.lang.reflect.TypeVariable;
+import java.lang.reflect.WildcardType;
 import java.security.AccessController;
 import java.security.PrivilegedAction;
 import java.util.ArrayList;
@@ -197,10 +198,18 @@
         if (genericType == null) {
             return null;
         }
-        if (!ParameterizedType.class.isAssignableFrom(genericType.getClass())) {
+        if (!ParameterizedType.class.isAssignableFrom(genericType.getClass())) { 
             if (genericType instanceof TypeVariable) {
                 genericType = getType(((TypeVariable)genericType).getBounds(), pos);
+            } else if (genericType instanceof WildcardType) { 
+                WildcardType wildcardType = (WildcardType)genericType;
+                Type[] bounds = wildcardType.getLowerBounds(); // '? extends Number'
+                if (bounds.length == 0) { 
+                    bounds = wildcardType.getUpperBounds(); // '? super Integer'
+                }
+                genericType = getType(bounds, pos);
             }
+            
             Class<?> cls = (Class<?>)genericType;
             return cls.isArray() ? cls.getComponentType() : cls;
         }


> WildcardTypeImpl cannot be cast to java.lang.Class - Class Cast exception thrown after
upgrading from 2.2.3 to 2.4.0
> --------------------------------------------------------------------------------------------------------------------
>
>                 Key: CXF-3470
>                 URL: https://issues.apache.org/jira/browse/CXF-3470
>             Project: CXF
>          Issue Type: Bug
>          Components: JAX-RS, JAXB Databinding
>    Affects Versions: 2.3.2, 2.4
>         Environment: java version "1.6.0_24"
> Java(TM) SE Runtime Environment (build 1.6.0_24-b07-334-10M3326)
> Java HotSpot(TM) 64-Bit Server VM (build 19.1-b02-334, mixed mode)
>            Reporter: Carlos Marin
>             Fix For: 2.2
>
>         Attachments: patch.txt
>
>
> My project was working fine with CXF version 2.2.3. After trying to upgrade to 2.3.2
and 2.4.0, in both cases I'm getting the following exception:
> java.lang.ClassCastException: sun.reflect.generics.reflectiveObjects.WildcardTypeImpl
cannot be cast to java.lang.Class
> 	at org.apache.cxf.jaxrs.utils.InjectionUtils.getActualType(InjectionUtils.java:204)
> 	at org.apache.cxf.jaxrs.utils.InjectionUtils.getActualType(InjectionUtils.java:209)
> 	at org.apache.cxf.jaxrs.utils.InjectionUtils.getActualType(InjectionUtils.java:209)
> 	at org.apache.cxf.jaxrs.utils.InjectionUtils.getActualType(InjectionUtils.java:192)
> 	at org.apache.cxf.jaxrs.provider.ProviderFactory.compareClasses(ProviderFactory.java:778)
> 	at org.apache.cxf.jaxrs.provider.ProviderFactory.access$400(ProviderFactory.java:61)
> 	at org.apache.cxf.jaxrs.provider.ProviderFactory$ClassComparator.compare(ProviderFactory.java:760)
> 	at java.util.Arrays.mergeSort(Arrays.java:1270)
> 	at java.util.Arrays.sort(Arrays.java:1210)
> 	at java.util.Collections.sort(Collections.java:159)
> 	at org.apache.cxf.jaxrs.provider.ProviderFactory.chooseMessageReader(ProviderFactory.java:508)
> 	at org.apache.cxf.jaxrs.provider.ProviderFactory.createMessageBodyReader(ProviderFactory.java:304)
> 	at org.apache.cxf.jaxrs.utils.JAXRSUtils.readFromMessageBody(JAXRSUtils.java:1004)
> 	at org.apache.cxf.jaxrs.utils.JAXRSUtils.processParameter(JAXRSUtils.java:594)
> 	at org.apache.cxf.jaxrs.utils.JAXRSUtils.processParameters(JAXRSUtils.java:559)
> 	at org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.processRequest(JAXRSInInterceptor.java:230)
> 	at org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.handleMessage(JAXRSInInterceptor.java:88)
> 	at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:263)
> 	at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:118)
> 	at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:208)
> 	at org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:223)
> 	at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:166)
> 	at org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:113)
> 	at org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:184)
> 	at org.apache.cxf.transport.servlet.AbstractHTTPServlet.doPost(AbstractHTTPServlet.java:107)
> 	at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
> 	at org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:163)
> 	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
> 	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
> ...
> 	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
> 	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
> 	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
> 	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
> 	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:563)
> 	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
> 	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
> 	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
> 	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
> 	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
> 	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
> 	at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
> 	at java.lang.Thread.run(Thread.java:680)
> Method declaration is like (not working in CXF v2.4.0... but worked fine in v2.2.3):
>     @POST
>     @Path("mypath")
>     @Consumes({"application/json", "application/xml"})
>     public JAXBElement<MyElement> methodName(JAXBElement<? extends ParentClass>
zzz)
> Workaround is to declare method like:
>     @POST
>     @Path("mypath")
>     @Consumes({"application/json", "application/xml"})
>     public JAXBElement<MyElement> methodName(ParentClass zzz)

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

Mime
View raw message