[ https://issues.apache.org/jira/browse/CXF-6297?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14380209#comment-14380209 ]
Dmitry Kozlov commented on CXF-6297: ------------------------------------ Ok, will do. Meanwhile, it's great to hear about global! :) I'd be happy to submit JIRA for this if needed. One note on global: * with current implementation I get different context on filter invocations. Namely, {{uriInfo}} and path params differ - first invocation gets top-level super-path and params only (e.g. {{/teams/123/members}}), while second gets the rest ({{/teams/123/members/456}}). So obviously with this change the expectation would be to retain second call removing the first. Thanks! > JAX-RS BeanValidation feature fails with NPE in > JAXRSBeanValidationOutInterceptor on sub-resource call > ------------------------------------------------------------------------------------------------------ > > Key: CXF-6297 > URL: https://issues.apache.org/jira/browse/CXF-6297 > Project: CXF > Issue Type: Bug > Components: JAX-RS > Affects Versions: 3.0.4 > Reporter: Dmitry Kozlov > Assignee: Sergey Beryozkin > Fix For: 3.1.0, 3.0.5 > > > With {{JAXRSBeanValidationFeature}} enabled CXF fails to process request to > sub-resource with exception like this: > {code} > 23:58:16.049 [qtp457732796-28] WARN o.a.cxf.phase.PhaseInterceptorChain - > Interceptor for {http://example.com/}MainResource has thrown exception, > unwinding now > java.lang.NullPointerException: null > at > org.apache.cxf.jaxrs.validation.ValidationUtils.getResourceInstance(ValidationUtils.java:39) > ~[cxf-rt-frontend-jaxrs-3.0.4.jar:3.0.4] > at > org.apache.cxf.jaxrs.validation.JAXRSBeanValidationOutInterceptor.getServiceObject(JAXRSBeanValidationOutInterceptor.java:44) > ~[cxf-rt-frontend-jaxrs-3.0.4.jar:3.0.4] > at > org.apache.cxf.validation.AbstractValidationInterceptor.handleMessage(AbstractValidationInterceptor.java:60) > ~[cxf-core-3.0.4.jar:3.0.4] > at > org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:307) > [cxf-core-3.0.4.jar:3.0.4] > at > org.apache.cxf.interceptor.OutgoingChainInterceptor.handleMessage(OutgoingChainInterceptor.java:83) > [cxf-core-3.0.4.jar:3.0.4] > at > org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:307) > [cxf-core-3.0.4.jar:3.0.4] > at > org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121) > [cxf-core-3.0.4.jar:3.0.4] > at > org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:251) > [cxf-rt-transports-http-3.0.4.jar:3.0.4] > at > org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:234) > [cxf-rt-transports-http-3.0.4.jar:3.0.4] > at > org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:208) > [cxf-rt-transports-http-3.0.4.jar:3.0.4] > at > org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:160) > [cxf-rt-transports-http-3.0.4.jar:3.0.4] > at > org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:171) > [cxf-rt-transports-http-3.0.4.jar:3.0.4] > at > org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:293) > [cxf-rt-transports-http-3.0.4.jar:3.0.4] > at > org.apache.cxf.transport.servlet.AbstractHTTPServlet.doGet(AbstractHTTPServlet.java:217) > [cxf-rt-transports-http-3.0.4.jar:3.0.4] > at javax.servlet.http.HttpServlet.service(HttpServlet.java:687) > [javax.servlet-api-3.1.0.jar:3.1.0] > at > org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:268) > [cxf-rt-transports-http-3.0.4.jar:3.0.4] > ... > {code} > The example resource code: > {code} > @Path("/main") > public interface MainResource { > @Path("/sub/{id}") > SubResource subResource(@PathParam @Size(min=3, max=255) String id); > } > ----- > public interface SubResource { > @GET > @Path("/items") > List<String> items(); > } > GET http://example.com/main/sub/123/items > {code} > NPE happens at > [ValidationUtils.java:39|https://github.com/apache/cxf/blob/c79696bfc1aee1d1204cbd592f6bc5c83c0d9dae/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/validation/ValidationUtils.java#L39], > since {{resourceProvider}} retrieved on previous line is {{null}}: > {code:java|firstline=33|highlight=39} > public static Object getResourceInstance(Message message) { > final OperationResourceInfo ori = > message.getExchange().get(OperationResourceInfo.class); > if (ori == null) { > return null; > } > final ResourceProvider resourceProvider = > ori.getClassResourceInfo().getResourceProvider(); > if (!resourceProvider.isSingleton()) { > String error = "Service object is not a singleton, use a custom > invoker to validate"; > LOG.warning(error); > return null; > } else { > return resourceProvider.getInstance(message); > } > {code} > This happens only during invocation of {{JAXRSBeanValidationOutInterceptor}} > and only when calling sub-resources as in example above. > h3. Partial Workaround > The partial workaround is to enable in-interceptor only. But this won't work > for people wishing to validate response entities as well. -- This message was sent by Atlassian JIRA (v6.3.4#6332)