mongo-java-server icon indicating copy to clipboard operation
mongo-java-server copied to clipboard

Issue when storing document with latest java drivers : java.lang.IllegalArgumentException: Document already contains field 'type'

Open dorpsidioot opened this issue 3 years ago • 2 comments

When trying to save this BsonDocument:

{
  "_t": "CS_PHYSICAL",
  "communicationUnit": {
    "id": {
      "$binary": {
        "base64": "c5j1hHJNSVCVX1DmWjbrCg==",
        "subType": "04"
      }
    },
    "protocol": "AUTOGENERATION",
    "type": "AUTOGENERATION",
    "unitIdentifier": "AUTO"
  },
  "endDate": {
    "$date": "9999-12-30T23:00:00Z"
  },
  "identifier": {
    "$binary": {
      "base64": "u3cyf0MZRcWChYSTsYrwBw==",
      "subType": "04"
    }
  },
  "mappingParameters": {
    "type": "AUTOGENERATED",
    "mode": "FIXED",
    "value": 1.0
  },
  "sourceId": {
    "$binary": {
      "base64": "u3cyf0MZRcWChYSTsYrwBw==",
      "subType": "04"
    }
  },
  "startDate": {
    "$date": "1999-12-31T23:00:00Z"
  },
  "type": "PHYSICAL"
}

I always encounter the following issue with the latest versions of mongo-java-server(was working with 4.1.2 driver and 1.27.0 mongo-java-server version):

SEVERE: exception for client bebf355b
io.netty.handler.codec.DecoderException: java.lang.IllegalArgumentException: Document already contains field 'type'
	at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:478)
	at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:276)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
	at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
	at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919)
	at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:166)
	at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:719)
	at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:655)
	at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:581)
	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:493)
	at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989)
	at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
	at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.IllegalArgumentException: Document already contains field 'type'
	at de.bwaldvogel.mongo.backend.Assert.isNull(Assert.java:78)
	at de.bwaldvogel.mongo.wire.bson.BsonDecoder.decodeBson(BsonDecoder.java:47)
	at de.bwaldvogel.mongo.wire.bson.BsonDecoder.decodeValue(BsonDecoder.java:59)
	at de.bwaldvogel.mongo.wire.bson.BsonDecoder.decodeBson(BsonDecoder.java:45)
	at de.bwaldvogel.mongo.wire.bson.BsonDecoder.decodeValue(BsonDecoder.java:59)
	at de.bwaldvogel.mongo.wire.bson.BsonDecoder.decodeBson(BsonDecoder.java:45)
	at de.bwaldvogel.mongo.wire.bson.BsonDecoder.decodeArray(BsonDecoder.java:104)
	at de.bwaldvogel.mongo.wire.bson.BsonDecoder.decodeValue(BsonDecoder.java:61)
	at de.bwaldvogel.mongo.wire.bson.BsonDecoder.decodeBson(BsonDecoder.java:45)
	at de.bwaldvogel.mongo.wire.bson.BsonDecoder.decodeValue(BsonDecoder.java:59)
	at de.bwaldvogel.mongo.wire.bson.BsonDecoder.decodeBson(BsonDecoder.java:45)
	at de.bwaldvogel.mongo.wire.MongoWireProtocolHandler.handleQuery(MongoWireProtocolHandler.java:182)
	at de.bwaldvogel.mongo.wire.MongoWireProtocolHandler.decode(MongoWireProtocolHandler.java:90)
	at de.bwaldvogel.mongo.wire.MongoWireProtocolHandler.decode(MongoWireProtocolHandler.java:34)
	at io.netty.handler.codec.LengthFieldBasedFrameDecoder.decode(LengthFieldBasedFrameDecoder.java:332)
	at io.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection(ByteToMessageDecoder.java:508)
	at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:447)
	... 16 more

dorpsidioot avatar May 17 '22 06:05 dorpsidioot

I always encounter the following issue with the latest versions of mongo-java-server(was working with 4.1.2 driver and 1.27.0 mongo-java-server version):

Version 1.27.0 of mongo-java-server is quite old (March 2020). Could you make sure that you test with the latest version?

Could you submit a unit test that reproduces the exception that you described?

bwaldvogel avatar May 22 '22 10:05 bwaldvogel

@bwaldvogel no what I meant that this error happens with newer versions of mongo-java-server (after 1.27.0)

dorpsidioot avatar May 31 '22 14:05 dorpsidioot

Closing for now. Please re-open if you are able to provide a (minimal) test case which reproduces the described issue.

bwaldvogel avatar Sep 12 '22 09:09 bwaldvogel