You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
With 5.0.4 snapshots, BasicErrorController is unable to return a response for validation failures. org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorControllerIntegrationTests.testRequestBodyValidationForMachineClient() fails due to a 500 response with an empty body being returned. The 500 and the empty body are due to a failure while writing the error controller's response:
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:687)
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:719)
at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:155)
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:727)
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:719)
at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:155)
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:727)
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:719)
at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:155)
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:727)
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:719)
at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:155)
at com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serializeContents(CollectionSerializer.java:145)
at com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serialize(CollectionSerializer.java:107)
at com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serialize(CollectionSerializer.java:25)
at com.fasterxml.jackson.databind.ser.std.MapSerializer.serializeFields(MapSerializer.java:718)
at com.fasterxml.jackson.databind.ser.std.MapSerializer.serialize(MapSerializer.java:639)
at com.fasterxml.jackson.databind.ser.std.MapSerializer.serialize(MapSerializer.java:33)
at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider._serialize(DefaultSerializerProvider.java:480)
at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:400)
at com.fasterxml.jackson.databind.ObjectWriter$Prefetch.serialize(ObjectWriter.java:1392)
at com.fasterxml.jackson.databind.ObjectWriter.writeValue(ObjectWriter.java:913)
at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.writeInternal(AbstractJackson2HttpMessageConverter.java:286)
at org.springframework.http.converter.AbstractGenericHttpMessageConverter.write(AbstractGenericHttpMessageConverter.java:102)
at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverters(AbstractMessageConverterMethodProcessor.java:271)
at org.springframework.web.servlet.mvc.method.annotation.HttpEntityMethodProcessor.handleReturnValue(HttpEntityMethodProcessor.java:218)
at org.springframework.web.method.support.HandlerMethodReturnValueHandlerComposite.handleReturnValue(HandlerMethodReturnValueHandlerComposite.java:82)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:119)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:870)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:776)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:991)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:925)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:978)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:881)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:661)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:855)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:728)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:472)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:395)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:316)
at org.apache.catalina.core.StandardHostValve.custom(StandardHostValve.java:395)
at org.apache.catalina.core.StandardHostValve.status(StandardHostValve.java:254)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:177)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:803)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:790)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1459)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.IndexOutOfBoundsException: Index: -1, Size: 0
at java.util.ArrayList$SubList.rangeCheck(ArrayList.java:1223)
at java.util.ArrayList$SubList.get(ArrayList.java:1040)
at org.hibernate.validator.internal.engine.path.PathImpl.<init>(PathImpl.java:375)
at org.hibernate.validator.internal.engine.path.PathImpl.getPathWithoutLeafNode(PathImpl.java:113)
... 63 more
Thanks, @jhoeller. I was just commenting to say that's the cause when your comment appeared. I think we need to fix this on our side as it's rather naive of BasicErrorController to assume that all of a BindingResult's errors will be suitable for serialisation to JSON.
I wouldn't be surprised if some other simple demo controllers do the same! Maybe we shouldn't have a bean-style getSource() accessor here but rather some different naming convention for that rather different purpose...
If you think a different naming convention is reasonable, it would certainly have the benefit of providing a solution for everyone who may be affected. If you stick with the current name, I think we'll create a DTO for the ObjectError instances so that we can hide the source. A change in name would be a smaller change.
I'm considering an unwrap(Class) style method, as known from Bean Validation itself. This would also allow for conveniently unwrapping the cause of the outermost exception which is what you're typically interested in. And with a contains(Class) kind of variant, one could conveniently check what kind of source a particular field error came from.
Pushed. This new pair of accessors turns out to be pretty convenient to use for the typical cases, so I actually prefer it over getSource() from a design perspective.
Activity
Start building against Spring Framework 5.0.4 snapshots
wilkinsona commentedon Feb 13, 2018
With 5.0.4 snapshots,
BasicErrorControlleris unable to return a response for validation failures.org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorControllerIntegrationTests.testRequestBodyValidationForMachineClient()fails due to a 500 response with an empty body being returned. The 500 and the empty body are due to a failure while writing the error controller's response:jhoeller commentedon Feb 13, 2018
Hmm, could this be related to https://jira.spring.io/browse/SPR-16372? Is it trying to serialize a
FieldErrorthere where we store theConstraintViolationobject now (but just in a transient field), and then it happens to arbitrarily fail somewhere in thatConstraintViolationobject graph?wilkinsona commentedon Feb 13, 2018
Thanks, @jhoeller. I was just commenting to say that's the cause when your comment appeared. I think we need to fix this on our side as it's rather naive of
BasicErrorControllerto assume that all of aBindingResult's errors will be suitable for serialisation to JSON.jhoeller commentedon Feb 13, 2018
I wouldn't be surprised if some other simple demo controllers do the same! Maybe we shouldn't have a bean-style
getSource()accessor here but rather some different naming convention for that rather different purpose...wilkinsona commentedon Feb 13, 2018
If you think a different naming convention is reasonable, it would certainly have the benefit of providing a solution for everyone who may be affected. If you stick with the current name, I think we'll create a DTO for the
ObjectErrorinstances so that we can hide the source. A change in name would be a smaller change.jhoeller commentedon Feb 13, 2018
I'm considering an
unwrap(Class)style method, as known from Bean Validation itself. This would also allow for conveniently unwrapping the cause of the outermost exception which is what you're typically interested in. And with acontains(Class)kind of variant, one could conveniently check what kind of source a particular field error came from.jhoeller commentedon Feb 13, 2018
Pushed. This new pair of accessors turns out to be pretty convenient to use for the typical cases, so I actually prefer it over
getSource()from a design perspective.wilkinsona commentedon Feb 13, 2018
Thanks, Juergen. That seems to have done the trick in my local testing. Hopefully CI will agree.
[-]Upgrade to Spring Framework 5.0.4[/-][+]Upgrade to Spring Framework 5.0.4.RELEASE[/+]