[JAVA-4334] NullPointerException in org.bson.codecs.Encoder.encode Created: 06/Oct/21  Updated: 04/May/22  Resolved: 11/Oct/21

Status: Closed
Project: Java Driver
Component/s: Async
Affects Version/s: 3.11.1
Fix Version/s: None

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

Issue Links:
Duplicate
is duplicated by JAVA-4335 AutomaticPojoCodec nested codec race ... Backlog

 Description   

I have a class that implements Codec<T>. In the `encode` method there was a NPE thrown but there was nothing in the logs. It took me a few hours to figure it out. That should be fixed so other people are not hit by this like me.

I'm using the latest version of the async Java driver.



 Comments   
Comment by Jeffrey Yemin [ 11/Oct/21 ]

Note: the stack trace indicate use of release 4.1.1, not, 3.11.1

Comment by Jeffrey Yemin [ 07/Oct/21 ]

Hi praveenmay03@gmail.com

Thanks for letting us know.  We'll look into it and get back to you.

 

Comment by Praveen D [ 06/Oct/21 ]

I am getting the below error while using the default codec:
{"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.\r\nDecoding into a 'Rules' failed with the following exception:\r\n\r\nFailed 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'\r\n\r\nA 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.\r\nDecoding into a 'Rules' failed with the following exception:\r\n\r\nFailed 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'\r\n\r\nA 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'\n\tat org.bson.codecs.pojo.PojoCodecImpl.decodePropertyModel(PojoCodecImpl.java:216) ~[bson-4.1.1.jar:?]\n\tat org.bson.codecs.pojo.PojoCodecImpl.decodeProperties(PojoCodecImpl.java:198) ~[bson-4.1.1.jar:?]\n\tat org.bson.codecs.pojo.PojoCodecImpl.decode(PojoCodecImpl.java:122) ~[bson-4.1.1.jar:?]\n\tat org.bson.codecs.pojo.PojoCodecImpl.decode(PojoCodecImpl.java:126) ~[bson-4.1.1.jar:?]\n\tat org.bson.codecs.pojo.LazyPojoCodec.decode(LazyPojoCodec.java:57) ~[bson-4.1.1.jar:?]\n\tat org.bson.codecs.DecoderContext.decodeWithChildContext(DecoderContext.java:96) ~[bson-4.1.1.jar:?]\n\tat org.bson.codecs.pojo.PojoCodecImpl.decodePropertyModel(PojoCodecImpl.java:219) ~[bson-4.1.1.jar:?]\n\tat org.bson.codecs.pojo.PojoCodecImpl.decodeProperties(PojoCodecImpl.java:198) ~[bson-4.1.1.jar:?]\n\tat org.bson.codecs.pojo.PojoCodecImpl.decode(PojoCodecImpl.java:122) ~[bson-4.1.1.jar:?]\n\tat org.bson.codecs.pojo.PojoCodecImpl.decode(PojoCodecImpl.java:126) ~[bson-4.1.1.jar:?]\n\tat org.bson.codecs.pojo.LazyPojoCodec.decode(LazyPojoCodec.java:57) ~[bson-4.1.1.jar:?]\n\tat org.bson.codecs.DecoderContext.decodeWithChildContext(DecoderContext.java:96) ~[bson-4.1.1.jar:?]\n\tat org.bson.codecs.pojo.PojoCodecImpl.decodePropertyModel(PojoCodecImpl.java:219) ~[bson-4.1.1.jar:?]\n\tat org.bson.codecs.pojo.PojoCodecImpl.decodeProperties(PojoCodecImpl.java:198) ~[bson-4.1.1.jar:?]\n\tat org.bson.codecs.pojo.PojoCodecImpl.decode(PojoCodecImpl.java:122) ~[bson-4.1.1.jar:?]\n\tat org.bson.codecs.pojo.PojoCodecImpl.decode(PojoCodecImpl.java:126) ~[bson-4.1.1.jar:?]\n\tat org.bson.codecs.pojo.AutomaticPojoCodec.decode(AutomaticPojoCodec.java:37) ~[bson-4.1.1.jar:?]\n\tat com.mongodb.internal.operation.CommandResultArrayCodec.decode(CommandResultArrayCodec.java:52) ~[mongodb-driver-core-4.1.1.jar:?]\n\tat com.mongodb.internal.operation.CommandResultDocumentCodec.readValue(CommandResultDocumentCodec.java:60) ~[mongodb-driver-core-4.1.1.jar:?]\n\tat org.bson.codecs.BsonDocumentCodec.decode(BsonDocumentCodec.java:87) ~[bson-4.1.1.jar:?]\n\tat org.bson.codecs.BsonDocumentCodec.decode(BsonDocumentCodec.java:42) ~[bson-4.1.1.jar:?]\n\tat org.bson.internal.LazyCodec.decode(LazyCodec.java:48) ~[bson-4.1.1.jar:?]\n\tat org.bson.codecs.BsonDocumentCodec.readValue(BsonDocumentCodec.java:104) ~[bson-4.1.1.jar:?]\n\tat com.mongodb.internal.operation.CommandResultDocumentCodec.readValue(CommandResultDocumentCodec.java:63) ~[mongodb-driver-core-4.1.1.jar:?]\n\tat org.bson.codecs.BsonDocumentCodec.decode(BsonDocumentCodec.java:87) ~[bson-4.1.1.jar:?]\n\tat org.bson.codecs.BsonDocumentCodec.decode(BsonDocumentCodec.java:42) ~[bson-4.1.1.jar:?]\n\tat com.mongodb.internal.connection.ReplyMessage.<init>(ReplyMessage.java:51) ~[mongodb-driver-core-4.1.1.jar:?]\n\tat com.mongodb.internal.connection.InternalStreamConnection.getCommandResult(InternalStreamConnection.java:477) ~[mongodb-driver-core-4.1.1.jar:?]\n\tat com.mongodb.internal.connection.InternalStreamConnection.access$1000(InternalStreamConnection.java:78) ~[mongodb-driver-core-4.1.1.jar:?]\n\tat com.mongodb.internal.connection.InternalStreamConnection$2$1.onResult(InternalStreamConnection.java:462) ~[mongodb-driver-core-4.1.1.jar:?]\n\tat com.mongodb.internal.connection.InternalStreamConnection$2$1.onResult(InternalStreamConnection.java:440) ~[mongodb-driver-core-4.1.1.jar:?]\n\tat com.mongodb.internal.connection.InternalStreamConnection$MessageHeaderCallback$MessageCallback.onResult(InternalStreamConnection.java:745) ~[mongodb-driver-core-4.1.1.jar:?]\n\tat com.mongodb.internal.connection.InternalStreamConnection$MessageHeaderCallback$MessageCallback.onResult(InternalStreamConnection.java:712) ~[mongodb-driver-core-4.1.1.jar:?]\n\tat com.mongodb.internal.connection.InternalStreamConnection$5.completed(InternalStreamConnection.java:582) ~[mongodb-driver-core-4.1.1.jar:?]\n\tat com.mongodb.internal.connection.InternalStreamConnection$5.completed(InternalStreamConnection.java:579) ~[mongodb-driver-core-4.1.1.jar:?]\n\tat com.mongodb.internal.connection.AsynchronousChannelStream$BasicCompletionHandler.completed(AsynchronousChannelStream.java:250) ~[mongodb-driver-core-4.1.1.jar:?]\n\tat com.mongodb.internal.connection.AsynchronousChannelStream$BasicCompletionHandler.completed(AsynchronousChannelStream.java:233) ~[mongodb-driver-core-4.1.1.jar:?]\n\tat sun.nio.ch.Invoker.invokeUnchecked(Invoker.java:127) ~[?:?]\n\tat sun.nio.ch.Invoker.invokeUnchecked(Invoker.java:282) ~[?:?]\n\tat sun.nio.ch.WindowsAsynchronousSocketChannelImpl$ReadTask.completed(WindowsAsynchronousSocketChannelImpl.java:581) ~[?:?]\n\tat sun.nio.ch.Iocp$EventHandlerTask.run(Iocp.java:387) ~[?:?]\n\tat sun.nio.ch.AsynchronousChannelGroupImpl$1.run(AsynchronousChannelGroupImpl.java:112) ~[?:?]\n\tat java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) ~[?:?]\n\tat java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) ~[?:?]\n\tat java.lang.Thread.run(Thread.java:830) ~[?:?]\n"}

,"extendedStackTrace":"org.bson.codecs.configuration.CodecConfigurationException: Failed to decode 'Criteria'. Decoding 'ifCriteria' errored with: Missing codec in 'Criteria' for 'ifCriteria'\n\tat org.bson.codecs.pojo.PojoCodecImpl.decodePropertyModel(PojoCodecImpl.java:225) ~[bson-4.1.1.jar:?]\n\tat org.bson.codecs.pojo.PojoCodecImpl.decodeProperties(PojoCodecImpl.java:198) ~[bson-4.1.1.jar:?]\n\tat

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