Skip to content

Commit 0b492b6

Browse files
christophstroblodrotbohm
authored andcommitted
DATAMONGO-1317 - Assert compatibility with mongo-java-driver 3.2.
We now do a defensive check against the actual WObject of WriteConcern to avoid the IllegalStateException raised by the new java-driver in case _w is null or not an Integer. This allows us to run against recent 2.13, 2.14, 3.0, 3.1 and the latest 3.2.0. Original pull request: #337.
1 parent b3116a5 commit 0b492b6

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoTemplate.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -775,11 +775,17 @@ protected void prepareCollection(DBCollection collection) {
775775
protected WriteConcern prepareWriteConcern(MongoAction mongoAction) {
776776

777777
WriteConcern wc = writeConcernResolver.resolve(mongoAction);
778+
return potentiallyForceAcknowledgedWrite(wc);
779+
}
780+
781+
private WriteConcern potentiallyForceAcknowledgedWrite(WriteConcern wc) {
778782

779-
if (MongoClientVersion.isMongo3Driver()
780-
&& ObjectUtils.nullSafeEquals(WriteResultChecking.EXCEPTION, writeResultChecking)
781-
&& (wc == null || wc.getW() < 1)) {
782-
return WriteConcern.ACKNOWLEDGED;
783+
if (ObjectUtils.nullSafeEquals(WriteResultChecking.EXCEPTION, writeResultChecking)
784+
&& MongoClientVersion.isMongo3Driver()) {
785+
if (wc == null || wc.getWObject() == null
786+
|| (wc.getWObject() instanceof Number && ((Number) wc.getWObject()).intValue() < 1)) {
787+
return WriteConcern.ACKNOWLEDGED;
788+
}
783789
}
784790
return wc;
785791
}

0 commit comments

Comments
 (0)