[JAVA-3668] null in message of CodecConfigurationException Created: 24/Mar/20  Updated: 28/Oct/23  Resolved: 20/Apr/20

Status: Closed
Project: Java Driver
Component/s: Codecs
Affects Version/s: 3.5.0
Fix Version/s: 3.6.0

Type: Bug Priority: Major - P3
Reporter: Kira Resari Assignee: Ross Lawley
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Windows 10, Eclipse 2019-12 (4.14.0)



 Description   

When trying to decode a complex object using the AutomaticPojoCodec, the following error happens:

org.bson.codecs.configuration.CodecConfigurationException: An exception occurred when decoding using the AutomaticPojoCodec.
Decoding into a 'ReqIF' failed with the following exception:
Failed to decode 'coreContent'. 
Failed to decode 'reqIF_content'. 
Failed to decode 'datatypes'. 
Failed to decode 'datatypeDefinitions'. 
An exception occurred when decoding using the AutomaticPojoCodec.
Decoding into a 'DatatypeDefinitionTag' failed with the following exception:
 
null
 
A custom Codec or PojoCodec may need to be explicitly configured and registered to handle this type.A custom Codec or PojoCodec may need to be explicitly configured and registered to handle this type.
	at org.bson.codecs.pojo.AutomaticPojoCodec.decode(AutomaticPojoCodec.java:40)
	at com.mongodb.operation.CommandResultArrayCodec.decode(CommandResultArrayCodec.java:52)
	at com.mongodb.operation.CommandResultDocumentCodec.readValue(CommandResultDocumentCodec.java:60)
	at org.bson.codecs.BsonDocumentCodec.decode(BsonDocumentCodec.java:84)
	at org.bson.codecs.BsonDocumentCodec.decode(BsonDocumentCodec.java:41)
	at org.bson.codecs.configuration.LazyCodec.decode(LazyCodec.java:47)
	at org.bson.codecs.BsonDocumentCodec.readValue(BsonDocumentCodec.java:101)
	at com.mongodb.operation.CommandResultDocumentCodec.readValue(CommandResultDocumentCodec.java:63)
	at org.bson.codecs.BsonDocumentCodec.decode(BsonDocumentCodec.java:84)
	at org.bson.codecs.BsonDocumentCodec.decode(BsonDocumentCodec.java:41)
	at com.mongodb.connection.ReplyMessage.<init>(ReplyMessage.java:50)
	at com.mongodb.connection.CommandProtocol.getResponseDocument(CommandProtocol.java:132)
	at com.mongodb.connection.CommandProtocol.execute(CommandProtocol.java:111)
	at com.mongodb.connection.DefaultServer$DefaultServerProtocolExecutor.execute(DefaultServer.java:159)
	at com.mongodb.connection.DefaultServerConnection.executeProtocol(DefaultServerConnection.java:289)
	at com.mongodb.connection.DefaultServerConnection.command(DefaultServerConnection.java:176)
	at com.mongodb.operation.CommandOperationHelper.executeWrappedCommandProtocol(CommandOperationHelper.java:216)
	at com.mongodb.operation.CommandOperationHelper.executeWrappedCommandProtocol(CommandOperationHelper.java:207)
	at com.mongodb.operation.CommandOperationHelper.executeWrappedCommandProtocol(CommandOperationHelper.java:113)
	at com.mongodb.operation.FindOperation$1.call(FindOperation.java:715)
	at com.mongodb.operation.FindOperation$1.call(FindOperation.java:709)
	at com.mongodb.operation.OperationHelper.withConnectionSource(OperationHelper.java:433)
	at com.mongodb.operation.OperationHelper.withConnection(OperationHelper.java:406)
	at com.mongodb.operation.FindOperation.execute(FindOperation.java:709)
	at com.mongodb.operation.FindOperation.execute(FindOperation.java:81)
	at com.mongodb.Mongo.execute(Mongo.java:810)
	at com.mongodb.Mongo$2.execute(Mongo.java:797)
	at com.mongodb.OperationIterable.iterator(OperationIterable.java:47)
	at com.mongodb.FindIterableImpl.iterator(FindIterableImpl.java:200)
	at com.mongodb.FindIterableImpl.iterator(FindIterableImpl.java:37)
	at io.cesonia.camelot.knight.reqIF.mongoDB.ReqIF_MongoDB_Reader.findByAddress(ReqIF_MongoDB_Reader.java:43)
	at io.cesonia.camelot.knight.reqIF.mongoDB.ReqIF_MongoDB_Reader.readReqIF_DataFromMongoDB(ReqIF_MongoDB_Reader.java:29)
	at io.cesonia.camelot.knight.reqIF.mongoDB.ReqIF_MongoDB_ReaderTest.readReqIF_DataFromMongoDB_shouldReturnReqIF_dataObject(ReqIF_MongoDB_ReaderTest.java:49)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:686)
	at org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain$ValidatingInvocation.proceed(InvocationInterceptorChain.java:131)
	at org.junit.jupiter.engine.extension.TimeoutExtension.intercept(TimeoutExtension.java:149)
	at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestableMethod(TimeoutExtension.java:140)
	at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestMethod(TimeoutExtension.java:84)
	at org.junit.jupiter.engine.execution.ExecutableInvoker$ReflectiveInterceptorCall.lambda$ofVoidMethod$0(ExecutableInvoker.java:115)
	at org.junit.jupiter.engine.execution.ExecutableInvoker.lambda$invoke$0(ExecutableInvoker.java:105)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:106)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain.proceed(InvocationInterceptorChain.java:64)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain.chainAndInvoke(InvocationInterceptorChain.java:45)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain.invoke(InvocationInterceptorChain.java:37)
	at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:104)
	at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:98)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$6(TestMethodTestDescriptor.java:205)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod(TestMethodTestDescriptor.java:201)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:137)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:71)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:135)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125)
	at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80)
	at java.util.ArrayList.forEach(Unknown Source)
	at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:139)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125)
	at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80)
	at java.util.ArrayList.forEach(Unknown Source)
	at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:139)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125)
	at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80)
	at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:32)
	at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)
	at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:51)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:248)
	at org.junit.platform.launcher.core.DefaultLauncher.lambda$execute$5(DefaultLauncher.java:211)
	at org.junit.platform.launcher.core.DefaultLauncher.withInterceptedStreams(DefaultLauncher.java:226)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:199)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:141)
	at org.eclipse.jdt.internal.junit5.runner.JUnit5TestReference.run(JUnit5TestReference.java:89)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:41)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:542)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:770)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:464)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:210)
Caused by: org.bson.codecs.configuration.CodecConfigurationException: Failed to decode 'coreContent'. Failed to decode 'reqIF_content'. Failed to decode 'datatypes'. Failed to decode 'datatypeDefinitions'. An exception occurred when decoding using the AutomaticPojoCodec.
Decoding into a 'DatatypeDefinitionTag' failed with the following exception:nullA custom Codec or PojoCodec may need to be explicitly configured and registered to handle this type.
	at org.bson.codecs.pojo.PojoCodecImpl.decodePropertyModel(PojoCodecImpl.java:173)
	at org.bson.codecs.pojo.PojoCodecImpl.decodeProperties(PojoCodecImpl.java:149)
	at org.bson.codecs.pojo.PojoCodecImpl.decode(PojoCodecImpl.java:103)
	at org.bson.codecs.pojo.PojoCodecImpl.decode(PojoCodecImpl.java:107)
	at org.bson.codecs.pojo.AutomaticPojoCodec.decode(AutomaticPojoCodec.java:37)
	... 97 more
Caused by: org.bson.codecs.configuration.CodecConfigurationException: Failed to decode 'reqIF_content'. Failed to decode 'datatypes'. Failed to decode 'datatypeDefinitions'. An exception occurred when decoding using the AutomaticPojoCodec.
Decoding into a 'DatatypeDefinitionTag' failed with the following exception:nullA custom Codec or PojoCodec may need to be explicitly configured and registered to handle this type.
	at org.bson.codecs.pojo.PojoCodecImpl.decodePropertyModel(PojoCodecImpl.java:173)
	at org.bson.codecs.pojo.PojoCodecImpl.decodeProperties(PojoCodecImpl.java:149)
	at org.bson.codecs.pojo.PojoCodecImpl.decode(PojoCodecImpl.java:103)
	at org.bson.codecs.pojo.PojoCodecImpl.decode(PojoCodecImpl.java:107)
	at org.bson.codecs.pojo.LazyPojoCodec.decode(LazyPojoCodec.java:55)
	at org.bson.codecs.DecoderContext.decodeWithChildContext(DecoderContext.java:93)
	at org.bson.codecs.pojo.PojoCodecImpl.decodePropertyModel(PojoCodecImpl.java:165)
	... 101 more
Caused by: org.bson.codecs.configuration.CodecConfigurationException: Failed to decode 'datatypes'. Failed to decode 'datatypeDefinitions'. An exception occurred when decoding using the AutomaticPojoCodec.
Decoding into a 'DatatypeDefinitionTag' failed with the following exception:nullA custom Codec or PojoCodec may need to be explicitly configured and registered to handle this type.
	at org.bson.codecs.pojo.PojoCodecImpl.decodePropertyModel(PojoCodecImpl.java:173)
	at org.bson.codecs.pojo.PojoCodecImpl.decodeProperties(PojoCodecImpl.java:149)
	at org.bson.codecs.pojo.PojoCodecImpl.decode(PojoCodecImpl.java:103)
	at org.bson.codecs.pojo.PojoCodecImpl.decode(PojoCodecImpl.java:107)
	at org.bson.codecs.pojo.LazyPojoCodec.decode(LazyPojoCodec.java:55)
	at org.bson.codecs.DecoderContext.decodeWithChildContext(DecoderContext.java:93)
	at org.bson.codecs.pojo.PojoCodecImpl.decodePropertyModel(PojoCodecImpl.java:165)
	... 107 more
Caused by: org.bson.codecs.configuration.CodecConfigurationException: Failed to decode 'datatypeDefinitions'. An exception occurred when decoding using the AutomaticPojoCodec.
Decoding into a 'DatatypeDefinitionTag' failed with the following exception:nullA custom Codec or PojoCodec may need to be explicitly configured and registered to handle this type.
	at org.bson.codecs.pojo.PojoCodecImpl.decodePropertyModel(PojoCodecImpl.java:173)
	at org.bson.codecs.pojo.PojoCodecImpl.decodeProperties(PojoCodecImpl.java:149)
	at org.bson.codecs.pojo.PojoCodecImpl.decode(PojoCodecImpl.java:103)
	at org.bson.codecs.pojo.PojoCodecImpl.decode(PojoCodecImpl.java:107)
	at org.bson.codecs.pojo.LazyPojoCodec.decode(LazyPojoCodec.java:55)
	at org.bson.codecs.DecoderContext.decodeWithChildContext(DecoderContext.java:93)
	at org.bson.codecs.pojo.PojoCodecImpl.decodePropertyModel(PojoCodecImpl.java:165)
	... 113 more
Caused by: org.bson.codecs.configuration.CodecConfigurationException: An exception occurred when decoding using the AutomaticPojoCodec.
Decoding into a 'DatatypeDefinitionTag' failed with the following exception:nullA custom Codec or PojoCodec may need to be explicitly configured and registered to handle this type.
	at org.bson.codecs.pojo.AutomaticPojoCodec.decode(AutomaticPojoCodec.java:40)
	at org.bson.codecs.pojo.CollectionCodec.decode(CollectionCodec.java:53)
	at org.bson.codecs.pojo.CollectionCodec.decode(CollectionCodec.java:30)
	at org.bson.codecs.DecoderContext.decodeWithChildContext(DecoderContext.java:93)
	at org.bson.codecs.pojo.PojoCodecImpl.decodePropertyModel(PojoCodecImpl.java:165)
	... 119 more
Caused by: org.bson.codecs.configuration.CodecConfigurationException
	at org.bson.codecs.pojo.CreatorExecutable.getInstance(CreatorExecutable.java:89)
	at org.bson.codecs.pojo.InstanceCreatorImpl.<init>(InstanceCreatorImpl.java:40)
	at org.bson.codecs.pojo.InstanceCreatorFactoryImpl.create(InstanceCreatorFactoryImpl.java:28)
	at org.bson.codecs.pojo.ClassModel.getInstanceCreator(ClassModel.java:70)
	at org.bson.codecs.pojo.PojoCodecImpl.decode(PojoCodecImpl.java:102)
	at org.bson.codecs.pojo.PojoCodecImpl.decode(PojoCodecImpl.java:107)
	at org.bson.codecs.pojo.AutomaticPojoCodec.decode(AutomaticPojoCodec.java:37)
	... 123 more
Caused by: java.lang.InstantiationException
	at sun.reflect.InstantiationExceptionConstructorAccessorImpl.newInstance(Unknown Source)
	at java.lang.reflect.Constructor.newInstance(Unknown Source)
	at org.bson.codecs.pojo.CreatorExecutable.getInstance(CreatorExecutable.java:84)
	... 129 more

My main issue here is this part:

Decoding into a 'DatatypeDefinitionTag' failed with the following exception:
 
null

At this place, a comprehensive messafe should be displayed, detailling why the decoding failed. However, in this case, this message is not displayed.

Following the stack trace to the end reveals this possible clue:

Caused by: java.lang.InstantiationException
	at sun.reflect.InstantiationExceptionConstructorAccessorImpl.newInstance(Unknown Source)
	at java.lang.reflect.Constructor.newInstance(Unknown Source)
	at org.bson.codecs.pojo.CreatorExecutable.getInstance(CreatorExecutable.java:84)

Since in my data model, the faulting class "DatatypeDefinitionTag" is an abstract class that is used like this in the parent class Datatypes:

List<DatatypeDefinitionTag> datatypeDefinitions

...where the elements that fill that list are members of the following classes:

public class DatatypeDefinitionString extends DatatypeDefinitionTag
public class DatatypeDefinitionInt extends DatatypeDefinitionTag
public class DatatypeDefinitionDate extends DatatypeDefinitionTag

...I could imagine that the actual issue is that the automatic decoder can't extract it since DatatypeDefinitionTag is an abstract class, and a custom codec is required to decode it.

In which case, the error message that appears in this place should read something like this:

org.bson.codecs.configuration.CodecConfigurationException: An exception occurred when decoding using the AutomaticPojoCodec.
Decoding into a 'ReqIF' failed with the following exception:
Failed to decode 'coreContent'. 
Failed to decode 'reqIF_content'. 
Failed to decode 'datatypes'. 
Failed to decode 'datatypeDefinitions'. 
An exception occurred when decoding using the AutomaticPojoCodec.
Decoding into a 'DatatypeDefinitionTag' failed with the following exception:
 
Abstract classes are not supported
 
A custom Codec or PojoCodec may need to be explicitly configured and registered to handle this type



 Comments   
Comment by Ross Lawley [ 20/Apr/20 ]

Thanks resari@cesonia.io for the ticket and the reproduction case.

The underlying bug was fixed in 3.6.0 and the latest 3.x version of the Mongo Java Driver is 3.12.3. I would recommend updating your driver to the latest version as it will contain bug fixes and new features.

All the best,

Ross Lawley

Comment by Kira Resari [ 25/Mar/20 ]

I created the following test project to replicate the bug (at the state of the Initial Commit) (run MongoDB_ReaderTest to replicate this issue)

https://github.com/Kira-Cesonia/MongoDB_TestProject

Comment by Kira Resari [ 24/Mar/20 ]

I also want to note that writing this object to MongoDB using the AutomaticPojoCodec works just fine.

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