2

When verifying the solution provided to Is there a way to get a variable in to a custom ConstraintValidator when using JAX-RS? i noticed that isValid is called twice and i doubt this is correct.

I can recreate the problem in the two WLP i have tried with:

  • WebSphere Application Server 19.0.0.2/wlp-1.0.25.cl190220190222-1311 on Java HotSpot(TM) 64-Bit Server VM, version 1.8.0_161-b12 (en_US)
  • WebSphere Application Server 19.0.0.5/wlp-1.0.28.cl190520190522-2227 on Java HotSpot(TM) 64-Bit Server VM, version 1.8.0_161-b12 (en_US)

server.xml

    <featureManager>
        <feature>jaxrs-2.1</feature>
        <feature>localConnector-1.0</feature>
        <feature>transportSecurity-1.0</feature>
        <feature>beanValidation-2.0</feature>
        <feature>jaxrsClient-2.1</feature>
        <feature>cdi-2.0</feature>
    </featureManager>

Can't find anything in the code that explains the double validation.

Stack dump shows that this happens in the same thread. First validation stack snippet:

.....
    ValidatorImpl.validateParameters(T, Method, Object[], Class<?>...) line: 224    
    BeanValidationProvider.validateParameters(T, Method, Object[]) line: 113    
    GeneratedMethodAccessor593.invoke(Object, Object[]) line: not available 
    Method.invoke(Object, Object...) line: not available    
    LibertyJaxRsInvoker.callValidationMethod(String, Object[], Object) line: 371    
    LibertyJaxRsInvoker.invoke(Exchange, Object, Method, List<Object>) line: 254    
    LibertyJaxRsInvoker(JAXRSInvoker).invoke(Exchange, Object, Object) line: 205    
.....

Second validation stack snippet a couple of ms later:

....
    ValidatorImpl.validateParameters(T, Method, Object[], Class<?>...) line: 224    
    ValidationInterceptor.validateMethodInvocation(InvocationContext) line: 66  
    GeneratedMethodAccessor662.invoke(Object, Object[]) line: not available 
    Method.invoke(Object, Object...) line: not available    
    SimpleInterceptorInvocation$SimpleMethodInvocation.invoke(InvocationContext) line: 73   
    InterceptorMethodHandler.executeAroundInvoke(Object, Method, Method, Object[], InterceptorMethodHandler$CachedInterceptionChain, InterceptionDecorationContext$Stack) line: 84  
    InterceptorMethodHandler.executeInterception(Object, Method, Method, Object[], InterceptionType, InterceptionDecorationContext$Stack) line: 72  
    InterceptorMethodHandler.invoke(InterceptionDecorationContext$Stack, Object, Method, Method, Object[]) line: 56 
    CombinedInterceptorAndDecoratorStackMethodHandler.invoke(InterceptionDecorationContext$Stack, Object, Method, Method, Object[], boolean, boolean) line: 79  
    CombinedInterceptorAndDecoratorStackMethodHandler.invoke(InterceptionDecorationContext$Stack, Object, Method, Method, Object[]) line: 68    
    CustomerResource$Proxy$_$$_WeldSubclass.postCustomer(Customer) line: not available  
    CustomerResource$Proxy$_$$_WeldClientProxy.postCustomer(Customer) line: not available   
    GeneratedMethodAccessor661.invoke(Object, Object[]) line: not available 
    Method.invoke(Object, Object...) line: not available    
    LibertyJaxRsServerFactoryBean.performInvocation(Exchange, Object, Method, Object[]) line: 652   
    LibertyJaxRsInvoker.performInvocation(Exchange, Object, Method, Object[]) line: 160 
    LibertyJaxRsInvoker(AbstractInvoker).invoke(Exchange, Object, Method, List<Object>) line: 96    
    LibertyJaxRsInvoker.invoke(Exchange, Object, Method, List<Object>) line: 273    
    LibertyJaxRsInvoker(JAXRSInvoker).invoke(Exchange, Object, Object) line: 205
....

Should not the validation be invoked only once?

  • 1
    This looks like a bug in Liberty - I haven't looked in depth yet, but it looks to me like the validation is occurring once as part of the JAX-RS processing and again as part of CDI processing. I would need to confer with my counterparts in the CDI area, but my guess is that the JAX-RS implementation code should defer bean validation to CDI when it knows that the resource class is a CDI managed bean. Can you open a GitHub issue? https://github.com/OpenLiberty/open-liberty/issues – Andy McCright Jun 05 '19 at 13:24
  • I have created the following github issue: https://github.com/OpenLiberty/open-liberty/issues/7755 – user2299548 Jun 05 '19 at 15:30

0 Answers0