jackson-databind: Intermittent failure to serialize payloads with `boolean` field (jackson 2.15.2)
Search before asking
- I searched in the issues and found nothing similar.
Describe the bug
getting - failed to serialize payload error for boolean field intermittently with java liberty servers, few times a week and then all the requests are getting same error until the server is restarted. we are using java 1.8, ibm websphere application server liberty 21.0.0.9 2.15.2 version of jackson databind
Version Information
2.15.2
Reproduction
<-- Any of the following
- Brief code sample/snippet: include here in preformatted/code section
- Longer example stored somewhere else (diff repo, snippet), add a link
- Textual explanation: include here –>
// Your code here
public class BaseRequest{
private boolean isStatus = false;
//getters, setters, few other fields
}
The payload is not having this field being sent, but intermittently we are getting failed to serialize payload error for this and then the particular server on which it started this error will start for all the other api calls and the server becomes non-responsive, after restart of the server the server becomes normal and no error for most of the time, and then happens once a week or two weeks
Expected behavior
no serialization error
Additional context
No response
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 25 (18 by maintainers)
Commits related to this issue
- Add test for #4715 in 2.15 (passing) — committed to ggrebert/jackson-databind by cowtowncoder 3 years ago
Discoveries
So I got curious about
GeneratedMethodAccessorXXX, and this is what I learned:GeneratedMethodAccessorXXXclasses are dynamically created byNativeMethodAccessorImplwhen.invoke(...)is called on the sameMethodinstance many times: https://github.com/openjdk/jdk8u/blob/e32d62e2a39510f643b32d615e76f0ff9be3d9f3/jdk/src/share/classes/sun/reflect/NativeMethodAccessorImpl.java#L49-L60Method.invoke(...)call - here’s a sample of how they look like:Method.invoke(...)call byDelegatingMethodAccessorImpl.nullBoolean wrapper to primitive), the accessor method itself will be included in the stack trace:GeneratedMethodAccessorXXXthrow NPE is by Jackson passingnullas first arg (i.e.bean) toMethod.invoke(...)here: https://github.com/FasterXML/jackson-databind/blob/74a57b2f6cd3b6e0fe2a61ed16734f15ba2abc95/src/main/java/com/fasterxml/jackson/databind/ser/BeanPropertyWriter.java#L688 …which is not technically possible because:ObjectMapper.writeValueAsString, i.e. what the caller passed to Jackson to serialize.ObjectMapper.writeValueAsStringall the way toBeanPropertyWriter.serializeAsField, none of the methods the arg was passed to ever re-assign it.nullor an NPE would’ve been thrown much, much earlier.Suspicious
Here are the things I found suspicious:
isStatusas property name?Conclusion (current)
Ignoring the suspicious
isStatusproperty name, my current hypothesis is:GeneratedMethodAccessorXXXclass.At this point we should probably stop @fc76gsk from throwing out questions, without giving answers to the questions asked 🤔
this is the same class, updated the name, pls check
This is the class
We are not able to reproduce this issue. Here is the stack trace: message=Service validation error. com.JavaException: txid=xxxxxxxxx: Failed to serialize payload of com.JavaClass at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1258) [com.ibm.ws.webcontainer_1.1.56.jar:?] at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:746) [com.ibm.ws.webcontainer_1.1.56.jar:?] at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:443) [com.ibm.ws.webcontainer_1.1.56.jar:?] at com.ibm.ws.webcontainer.filter.WebAppFilterManager.invokeFilters(WebAppFilterManager.java:1227) [com.ibm.ws.webcontainer_1.1.56.jar:?] at com.ibm.ws.webcontainer.filter.WebAppFilterManager.invokeFilters(WebAppFilterManager.java:1011) [com.ibm.ws.webcontainer_1.1.56.jar:?] at com.ibm.ws.webcontainer.servlet.CacheServletWrapper.handleRequest(CacheServletWrapper.java:75) [com.ibm.ws.webcontainer_1.1.56.jar:?] at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:938) [com.ibm.ws.webcontainer_1.1.56.jar:?] at com.ibm.ws.webcontainer.osgi.DynamicVirtualHost$2.run(DynamicVirtualHost.java:279) [com.ibm.ws.webcontainer_1.1.56.jar:?] at com.ibm.ws.http.dispatcher.internal.channel.HttpDispatcherLink$TaskWrapper.run(HttpDispatcherLink.java:1159) [com.ibm.ws.transport.http_1.0.56.jar:?] at com.ibm.ws.http.dispatcher.internal.channel.HttpDispatcherLink.wrapHandlerAndExecute(HttpDispatcherLink.java:428) [com.ibm.ws.transport.http_1.0.56.jar:?] at com.ibm.ws.http.dispatcher.internal.channel.HttpDispatcherLink.ready(HttpDispatcherLink.java:387) [com.ibm.ws.transport.http_1.0.56.jar:?] at com.ibm.ws.http.channel.internal.inbound.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:566) [com.ibm.ws.transport.http_1.0.56.jar:?] at com.ibm.ws.http.channel.internal.inbound.HttpInboundLink.handleNewRequest(HttpInboundLink.java:500) [com.ibm.ws.transport.http_1.0.56.jar:?] at com.ibm.ws.http.channel.internal.inbound.HttpInboundLink.processRequest(HttpInboundLink.java:360) [com.ibm.ws.transport.http_1.0.56.jar:?] at com.ibm.ws.http.channel.internal.inbound.HttpICLReadCallback.complete(HttpICLReadCallback.java:70) [com.ibm.ws.transport.http_1.0.56.jar:?] at com.ibm.ws.channel.ssl.internal.SSLReadServiceContext$SSLReadCompletedCallback.complete(SSLReadServiceContext.java:1824) [com.ibm.ws.channel.ssl_1.0.56.jar:?] at com.ibm.ws.tcpchannel.internal.WorkQueueManager.requestComplete(WorkQueueManager.java:504) [com.ibm.ws.channelfw_1.0.56.jar:?] at com.ibm.ws.tcpchannel.internal.WorkQueueManager.attemptIO(WorkQueueManager.java:574) [com.ibm.ws.channelfw_1.0.56.jar:?] at com.ibm.ws.tcpchannel.internal.WorkQueueManager.workerRun(WorkQueueManager.java:958) [com.ibm.ws.channelfw_1.0.56.jar:?] at com.ibm.ws.tcpchannel.internal.WorkQueueManager$Worker.run(WorkQueueManager.java:1047) [com.ibm.ws.channelfw_1.0.56.jar:?] at com.ibm.ws.threading.internal.ExecutorServiceImpl$RunnableWrapper.run(ExecutorServiceImpl.java:238) [com.ibm.ws.threading_1.1.56.jar:?] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1160) [?:1.8.0] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) [?:1.8.0] at java.lang.Thread.run(Thread.java:818) [?:2.9 (09-11-2019)] Caused by: com.fasterxml.jackson.databind.JsonMappingException: (was java.lang.NullPointerException) (through reference chain: com.JavaClass[“isStatus”]) at com.fasterxml.jackson.databind.JsonMappingException.wrapWithPath(JsonMappingException.java:402) ~[com.fasterxml.jackson.core-jackson-databind-2.15.2.jar:2.15.2] at com.fasterxml.jackson.databind.JsonMappingException.wrapWithPath(JsonMappingException.java:361) ~[com.fasterxml.jackson.core-jackson-databind-2.15.2.jar:2.15.2] at com.fasterxml.jackson.databind.ser.std.StdSerializer.wrapAndThrow(StdSerializer.java:323) ~[com.fasterxml.jackson.core-jackson-databind-2.15.2.jar:2.15.2] at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:780) ~[com.fasterxml.jackson.core-jackson-databind-2.15.2.jar:2.15.2] at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:178) ~[com.fasterxml.jackson.core-jackson-databind-2.15.2.jar:2.15.2] at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider._serialize(DefaultSerializerProvider.java:479) ~[com.fasterxml.jackson.core-jackson-databind-2.15.2.jar:2.15.2] at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:318) ~[com.fasterxml.jackson.core-jackson-databind-2.15.2.jar:2.15.2] at com.fasterxml.jackson.databind.ObjectMapper._writeValueAndClose(ObjectMapper.java:4719) ~[com.fasterxml.jackson.core-jackson-databind-2.15.2.jar:2.15.2] at com.fasterxml.jackson.databind.ObjectMapper.writeValueAsString(ObjectMapper.java:3964) ~[com.fasterxml.jackson.core-jackson-databind-2.15.2.jar:2.15.2] … 35 more Caused by: java.lang.NullPointerException at sun.reflect.GeneratedMethodAccessor961.invoke(Unknown Source) ~[?:?] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:55) ~[?:1.8.0] at java.lang.reflect.Method.invoke(Method.java:508) ~[?:1.8.0] at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:688) ~[com.fasterxml.jackson.core-jackson-databind-2.15.2.jar:2.15.2] at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:772) ~[com.fasterxml.jackson.core-jackson-databind-2.15.2.jar:2.15.2] at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:178) ~[com.fasterxml.jackson.core-jackson-databind-2.15.2.jar:2.15.2] at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider._serialize(DefaultSerializerProvider.java:479) ~[com.fasterxml.jackson.core-jackson-databind-2.15.2.jar:2.15.2] at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:318) ~[com.fasterxml.jackson.core-jackson-databind-2.15.2.jar:2.15.2] at com.fasterxml.jackson.databind.ObjectMapper._writeValueAndClose(ObjectMapper.java:4719) ~[com.fasterxml.jackson.core-jackson-databind-2.15.2.jar:2.15.2] at com.fasterxml.jackson.databind.ObjectMapper.writeValueAsString(ObjectMapper.java:3964) ~[com.fasterxml.jackson.core-jackson-databind-2.15.2.jar:2.15.2] … 35 more
Can you at least share the stack trace of the error?
This is just my opinion. This issue is super hard to reproduce and there are lots of moving parts. If this was my problem, I would try replacing the code that I suspect. There are lots of alternative libraries for working with JSON. In a few weeks, you will know if replacing the code has fixed the issue. If it hasn’t you need to then focus on something else to find the cause.
What we need is a reproduction. Jackson-only reproduction to be more specific. Without seeing how it is used, we cannot tell what is causing the problem