[JAVA-4335] AutomaticPojoCodec nested codec race condition Created: 06/Oct/21  Updated: 09/Oct/23

Status: Backlog
Project: Java Driver
Component/s: Codecs, POJO
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Praveen D Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: external-user
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates JAVA-4334 NullPointerException in org.bson.code... Closed
Quarter: FY24Q4
Documentation Changes Summary:

1. What would you like to communicate to the user about this feature?
2. Would you like the user to see examples of the syntax and/or executable code and its output?
3. Which versions of the driver/connector does this apply to?


 Description   

We are facing NullPointerException while saving and fetching the data using default codec:

We are using mongo-reactive-client-4.1.1 library, Kotlin for our application tech stack.
The issue is very inconsistent, when one thread try to save it works but when 50 threads try to save it fails with codec encoding issue. Once the encoding issue appeared then most of the request fails. 

Note:
Added the error message in comments.



 Comments   
Comment by Ross Lawley [ 12/Oct/21 ]

Hi praveenmay03@gmail.com,

Could you provide an example of the Pojos you are using? It may be helpful in replicating this issue.

Thanks again,

Ross

Comment by Ross Lawley [ 12/Oct/21 ]

HI praveenmay03@gmail.com,

Thanks for the report,

I can't see an NPE exception but the stacktrace reports a CodecConfigurtationException.

The fix is listed in the exception message:

Failed to decode 'Rules'. Decoding 'rule' errored with: Failed to decode 'Rule'. Decoding 'criteria' errored with: Failed to decode 'Criteria'. Decoding 'ifCriteria' errored with: Missing codec in 'Criteria' for 'ifCriteria'
 
*A custom Codec or PojoCodec may need to be explicitly configured and registered to handle this type.*","message":"An exception occurred when decoding using the AutomaticPojoCodec.
Decoding into a 'Rules' failed with the following exception:
 
Failed to decode 'Rules'. Decoding 'rule' errored with: Failed to decode 'Rule'. Decoding 'criteria' errored with: Failed to decode 'Criteria'. Decoding 'ifCriteria' errored with: Missing codec in 'Criteria' for 'ifCriteria'

Explicitly registering the PojoCodec for this class should fix the decoding issue.

I will leave this ticket open as the automatic pojo codec should be able to handle this issue and as you state: "The issue is very inconsistent, when one thread try to save it works but when 50 threads try to save it fails with codec encoding issue. Once the encoding issue appeared then most of the request fails. "

Many thanks,

Ross

Comment by Jeffrey Yemin [ 07/Oct/21 ]

Hi praveenmay03@gmail.com.

Thanks for reporting this issue.  We will investigate and get back to you soon.

Comment by Praveen D [ 06/Oct/21 ]

Below given the error details:

{"timeMillis":1633517884780,"thread":"Thread-12","level":"ERROR","loggerName":"com.test.springboot.webfluxmodule.library.filters.ObservabilityFilter","message":"Response Error","thrown":\{"commonElementCount":0,"name":"com.test.springboot.exceptionmodule.entities.exception.UnhandledException","cause":{"commonElementCount":0,"localizedMessage":"An exception occurred when decoding using the AutomaticPojoCodec.
Decoding into a 'Rules' failed with the following exception:
 
Failed to decode 'Rules'. Decoding 'rule' errored with: Failed to decode 'Rule'. Decoding 'criteria' errored with: Failed to decode 'Criteria'. Decoding 'ifCriteria' errored with: Missing codec in 'Criteria' for 'ifCriteria'
 
A custom Codec or PojoCodec may need to be explicitly configured and registered to handle this type.","message":"An exception occurred when decoding using the AutomaticPojoCodec.
Decoding into a 'Rules' failed with the following exception:
 
Failed to decode 'Rules'. Decoding 'rule' errored with: Failed to decode 'Rule'. Decoding 'criteria' errored with: Failed to decode 'Criteria'. Decoding 'ifCriteria' errored with: Missing codec in 'Criteria' for 'ifCriteria'
 
A custom Codec or PojoCodec may need to be explicitly configured and registered to handle this type.","name":"org.bson.codecs.configuration.CodecConfigurationException","cause":{"commonElementCount":0,"localizedMessage":"Failed to decode 'Rules'. Decoding 'rule' errored with: Failed to decode 'Rule'. Decoding 'criteria' errored with: Failed to decode 'Criteria'. Decoding 'ifCriteria' errored with: Missing codec in 'Criteria' for 'ifCriteria'","message":"Failed to decode 'Rules'. Decoding 'rule' errored with: Failed to decode 'Rule'. Decoding 'criteria' errored with: Failed to decode 'Criteria'. Decoding 'ifCriteria' errored with: Missing codec in 'Criteria' for 'ifCriteria'","name":"org.bson.codecs.configuration.CodecConfigurationException","cause":{"commonElementCount":0,"localizedMessage":"Failed to decode 'Rule'. Decoding 'criteria' errored with: Failed to decode 'Criteria'. Decoding 'ifCriteria' errored with: Missing codec in 'Criteria' for 'ifCriteria'","message":"Failed to decode 'Rule'. Decoding 'criteria' errored with: Failed to decode 'Criteria'. Decoding 'ifCriteria' errored with: Missing codec in 'Criteria' for 'ifCriteria'","name":"org.bson.codecs.configuration.CodecConfigurationException","cause":{"commonElementCount":0,"localizedMessage":"Failed to decode 'Criteria'. Decoding 'ifCriteria' errored with: Missing codec in 'Criteria' for 'ifCriteria'","message":"Failed to decode 'Criteria'. Decoding 'ifCriteria' errored with: Missing codec in 'Criteria' for 'ifCriteria'","name":"org.bson.codecs.configuration.CodecConfigurationException","cause":{"commonElementCount":0,"localizedMessage":"Missing codec in 'Criteria' for 'ifCriteria'","message":"Missing codec in 'Criteria' for 'ifCriteria'","name":"org.bson.codecs.configuration.CodecConfigurationException","extendedStackTrace":"org.bson.codecs.configuration.CodecConfigurationException: Missing codec in 'Criteria' for 'ifCriteria'
    at org.bson.codecs.pojo.PojoCodecImpl.decodePropertyModel(PojoCodecImpl.java:216) ~[bson-4.1.1.jar:?]
    at org.bson.codecs.pojo.PojoCodecImpl.decodeProperties(PojoCodecImpl.java:198) ~[bson-4.1.1.jar:?]
    at org.bson.codecs.pojo.PojoCodecImpl.decode(PojoCodecImpl.java:122) ~[bson-4.1.1.jar:?]
    at org.bson.codecs.pojo.PojoCodecImpl.decode(PojoCodecImpl.java:126) ~[bson-4.1.1.jar:?]
    at org.bson.codecs.pojo.LazyPojoCodec.decode(LazyPojoCodec.java:57) ~[bson-4.1.1.jar:?]
    at org.bson.codecs.DecoderContext.decodeWithChildContext(DecoderContext.java:96) ~[bson-4.1.1.jar:?]
    at org.bson.codecs.pojo.PojoCodecImpl.decodePropertyModel(PojoCodecImpl.java:219) ~[bson-4.1.1.jar:?]
    at org.bson.codecs.pojo.PojoCodecImpl.decodeProperties(PojoCodecImpl.java:198) ~[bson-4.1.1.jar:?]
    at org.bson.codecs.pojo.PojoCodecImpl.decode(PojoCodecImpl.java:122) ~[bson-4.1.1.jar:?]
    at org.bson.codecs.pojo.PojoCodecImpl.decode(PojoCodecImpl.java:126) ~[bson-4.1.1.jar:?]
    at org.bson.codecs.pojo.LazyPojoCodec.decode(LazyPojoCodec.java:57) ~[bson-4.1.1.jar:?]
    at org.bson.codecs.DecoderContext.decodeWithChildContext(DecoderContext.java:96) ~[bson-4.1.1.jar:?]
    at org.bson.codecs.pojo.PojoCodecImpl.decodePropertyModel(PojoCodecImpl.java:219) ~[bson-4.1.1.jar:?]
    at org.bson.codecs.pojo.PojoCodecImpl.decodeProperties(PojoCodecImpl.java:198) ~[bson-4.1.1.jar:?]
    at org.bson.codecs.pojo.PojoCodecImpl.decode(PojoCodecImpl.java:122) ~[bson-4.1.1.jar:?]
    at org.bson.codecs.pojo.PojoCodecImpl.decode(PojoCodecImpl.java:126) ~[bson-4.1.1.jar:?]
    at org.bson.codecs.pojo.AutomaticPojoCodec.decode(AutomaticPojoCodec.java:37) ~[bson-4.1.1.jar:?]
    at com.mongodb.internal.operation.CommandResultArrayCodec.decode(CommandResultArrayCodec.java:52) ~[mongodb-driver-core-4.1.1.jar:?]
    at com.mongodb.internal.operation.CommandResultDocumentCodec.readValue(CommandResultDocumentCodec.java:60) ~[mongodb-driver-core-4.1.1.jar:?]
    at org.bson.codecs.BsonDocumentCodec.decode(BsonDocumentCodec.java:87) ~[bson-4.1.1.jar:?]
    at org.bson.codecs.BsonDocumentCodec.decode(BsonDocumentCodec.java:42) ~[bson-4.1.1.jar:?]
    at org.bson.internal.LazyCodec.decode(LazyCodec.java:48) ~[bson-4.1.1.jar:?]
    at org.bson.codecs.BsonDocumentCodec.readValue(BsonDocumentCodec.java:104) ~[bson-4.1.1.jar:?]
    at com.mongodb.internal.operation.CommandResultDocumentCodec.readValue(CommandResultDocumentCodec.java:63) ~[mongodb-driver-core-4.1.1.jar:?]
    at org.bson.codecs.BsonDocumentCodec.decode(BsonDocumentCodec.java:87) ~[bson-4.1.1.jar:?]
    at org.bson.codecs.BsonDocumentCodec.decode(BsonDocumentCodec.java:42) ~[bson-4.1.1.jar:?]
    at com.mongodb.internal.connection.ReplyMessage.<init>(ReplyMessage.java:51) ~[mongodb-driver-core-4.1.1.jar:?]
    at com.mongodb.internal.connection.InternalStreamConnection.getCommandResult(InternalStreamConnection.java:477) ~[mongodb-driver-core-4.1.1.jar:?]
    at com.mongodb.internal.connection.InternalStreamConnection.access$1000(InternalStreamConnection.java:78) ~[mongodb-driver-core-4.1.1.jar:?]
    at com.mongodb.internal.connection.InternalStreamConnection$2$1.onResult(InternalStreamConnection.java:462) ~[mongodb-driver-core-4.1.1.jar:?]
    at com.mongodb.internal.connection.InternalStreamConnection$2$1.onResult(InternalStreamConnection.java:440) ~[mongodb-driver-core-4.1.1.jar:?]
    at com.mongodb.internal.connection.InternalStreamConnection$MessageHeaderCallback$MessageCallback.onResult(InternalStreamConnection.java:745) ~[mongodb-driver-core-4.1.1.jar:?]
    at com.mongodb.internal.connection.InternalStreamConnection$MessageHeaderCallback$MessageCallback.onResult(InternalStreamConnection.java:712) ~[mongodb-driver-core-4.1.1.jar:?]
    at com.mongodb.internal.connection.InternalStreamConnection$5.completed(InternalStreamConnection.java:582) ~[mongodb-driver-core-4.1.1.jar:?]
    at com.mongodb.internal.connection.InternalStreamConnection$5.completed(InternalStreamConnection.java:579) ~[mongodb-driver-core-4.1.1.jar:?]
    at com.mongodb.internal.connection.AsynchronousChannelStream$BasicCompletionHandler.completed(AsynchronousChannelStream.java:250) ~[mongodb-driver-core-4.1.1.jar:?]
    at com.mongodb.internal.connection.AsynchronousChannelStream$BasicCompletionHandler.completed(AsynchronousChannelStream.java:233) ~[mongodb-driver-core-4.1.1.jar:?]
    at sun.nio.ch.Invoker.invokeUnchecked(Invoker.java:127) ~[?:?]
    at sun.nio.ch.Invoker.invokeUnchecked(Invoker.java:282) ~[?:?]
    at sun.nio.ch.WindowsAsynchronousSocketChannelImpl$ReadTask.completed(WindowsAsynchronousSocketChannelImpl.java:581) ~[?:?]
    at sun.nio.ch.Iocp$EventHandlerTask.run(Iocp.java:387) ~[?:?]
    at sun.nio.ch.AsynchronousChannelGroupImpl$1.run(AsynchronousChannelGroupImpl.java:112) ~[?:?]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) ~[?:?]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) ~[?:?]
    at java.lang.Thread.run(Thread.java:830) ~[?:?]
"},"extendedStackTrace":"org.bson.codecs.configuration.CodecConfigurationException: Failed to decode 'Criteria'. Decoding 'ifCriteria' errored with: Missing codec in 'Criteria' for 'ifCriteria'
    at org.bson.codecs.pojo.PojoCodecImpl.decodePropertyModel(PojoCodecImpl.java:225) ~[bson-4.1.1.jar:?]
    at org.bson.codecs.pojo.PojoCodecImpl.decodeProperties(PojoCodecImpl.java:198) ~[bson-4.1.1.jar:?]
    at

Generated at Thu Feb 08 09:01:48 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.