[JAVA-3267] Mismatch between Javadocs and exception thrown when a write concern cannot be fulfilled Created: 15/Apr/19  Updated: 28/Oct/23  Resolved: 13/May/19

Status: Closed
Project: Java Driver
Component/s: Write Operations
Affects Version/s: 3.8.2
Fix Version/s: 3.11.0

Type: Bug Priority: Major - P3
Reporter: Nic Cottrell Assignee: Ross Lawley
Resolution: Fixed Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
Case:

 Description   

mongodb-driver-sync” (v3.8.2)

A `MongoCommandException` is thrown in `replaceOne` when a write concern cannot be fulfilled. But the Javadocs say it should be a `MongoWriteConcernException ` 

An example stacktrace:

com.mongodb.MongoCommandException: Command failed with error 64 (WriteConcernFailed): 'waiting for replication timed out; Error details: { wtimeout: true }' on server <HOST>:<p>. The full response is { "ok" : 0.0, "errmsg" : "waiting for replication timed out; Error details: { wtimeout: true }", "code" : 64, "codeName" : "WriteConcernFailed", "operationTime" : { "$timestamp" : { "t" : 1555309144, "i" : 1 } }, "$clusterTime" : { "clusterTime" : { "$timestamp" : { "t" : 1555309144, "i" : 1 } }, "signature" : { "hash" : { "$binary" : "0oD+9Fb/yWy62TNt56fQ821auf8=", "$type" : "00" }, "keyId" : { "$numberLong" : "6634436738045444126" } } } }
at com.mongodb.internal.connection.ProtocolHelper.getCommandFailureException(ProtocolHelper.java:179) ~[mongodb-driver-core-3.8.2.jar:na]
at com.mongodb.internal.connection.InternalStreamConnection.receiveCommandMessageResponse(InternalStreamConnection.java:293) ~[mongodb-driver-core-3.8.2.jar:na]
at com.mongodb.internal.connection.InternalStreamConnection.sendAndReceive(InternalStreamConnection.java:255) ~[mongodb-driver-core-3.8.2.jar:na]
at com.mongodb.internal.connection.UsageTrackingInternalConnection.sendAndReceive(UsageTrackingInternalConnection.java:99) ~[mongodb-driver-core-3.8.2.jar:na]
at com.mongodb.internal.connection.DefaultConnectionPool$PooledConnection.sendAndReceive(DefaultConnectionPool.java:444) ~[mongodb-driver-core-3.8.2.jar:na]
at com.mongodb.internal.connection.CommandProtocolImpl.execute(CommandProtocolImpl.java:72) ~[mongodb-driver-core-3.8.2.jar:na]
at com.mongodb.internal.connection.DefaultServer$DefaultServerProtocolExecutor.execute(DefaultServer.java:200) ~[mongodb-driver-core-3.8.2.jar:na]
at com.mongodb.internal.connection.DefaultServerConnection.executeProtocol(DefaultServerConnection.java:269) ~[mongodb-driver-core-3.8.2.jar:na]
at com.mongodb.internal.connection.DefaultServerConnection.command(DefaultServerConnection.java:131) ~[mongodb-driver-core-3.8.2.jar:na]
at com.mongodb.operation.MixedBulkWriteOperation.executeCommand(MixedBulkWriteOperation.java:418) ~[mongodb-driver-core-3.8.2.jar:na]
at com.mongodb.operation.MixedBulkWriteOperation.executeBulkWriteBatch(MixedBulkWriteOperation.java:256) ~[mongodb-driver-core-3.8.2.jar:na]
at com.mongodb.operation.MixedBulkWriteOperation.access$700(MixedBulkWriteOperation.java:67) ~[mongodb-driver-core-3.8.2.jar:na]
at com.mongodb.operation.MixedBulkWriteOperation$1.call(MixedBulkWriteOperation.java:200) ~[mongodb-driver-core-3.8.2.jar:na]
at com.mongodb.operation.MixedBulkWriteOperation$1.call(MixedBulkWriteOperation.java:191) ~[mongodb-driver-core-3.8.2.jar:na]
at com.mongodb.operation.OperationHelper.withReleasableConnection(OperationHelper.java:424) ~[mongodb-driver-core-3.8.2.jar:na]
at com.mongodb.operation.MixedBulkWriteOperation.execute(MixedBulkWriteOperation.java:191) ~[mongodb-driver-core-3.8.2.jar:na]
at com.mongodb.operation.MixedBulkWriteOperation.execute(MixedBulkWriteOperation.java:67) ~[mongodb-driver-core-3.8.2.jar:na]
at com.mongodb.client.internal.MongoClientDelegate$DelegateOperationExecutor.execute(MongoClientDelegate.java:193) ~[mongodb-driver-sync-3.8.2.jar:na]
at com.mongodb.client.internal.MongoCollectionImpl.executeSingleWriteRequest(MongoCollectionImpl.java:960) ~[mongodb-driver-sync-3.8.2.jar:na]
at com.mongodb.client.internal.MongoCollectionImpl.executeReplaceOne(MongoCollectionImpl.java:602) ~[mongodb-driver-sync-3.8.2.jar:na]
at com.mongodb.client.internal.MongoCollectionImpl.replaceOne(MongoCollectionImpl.java:578) ~[mongodb-driver-sync-3.8.2.jar:na]

 

There seem to be at least two solutions:

  1. Update the Javadocs
  2. Catch this MongoCommandException and wrap in MongoWriteConcernException


 Comments   
Comment by Githook User [ 13/May/19 ]

Author:

{'email': 'ross.lawley@gmail.com', 'name': 'Ross Lawley', 'username': 'rozza'}

Message: Updated Java doc to include MongoCommandException

JAVA-3267
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/bcd29eaed31cbe377a00f36fc734a1f14c9d55a1

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