vert-x3 / vertx-mongo-client

Mongo Client for Eclipse Vert.x
http://vertx.io
Apache License 2.0
58 stars 98 forks source link

java.lang.NullPointerException in BulkOperation constructor. #280

Closed matter-it-does closed 2 years ago

matter-it-does commented 2 years ago

Version

Java version 8

vertx mongo client version 4.2.5

Context

The constructor of BulkOperation prevents using a setter pattern as shown in the repro.

Since the map contains no "upsert" key, it returns null and the cast to Boolean throws the exception. better would be to catch it, set upsert and multi to false or defaults. And let user use setter later.

java.lang.NullPointerException
 at io.vertx.ext.mongo.BulkOperation.(BulkOperation.java:57)
public BulkOperation(JsonObject json) {
    String typeValue = json.getString("type");
    type = typeValue != null ? BulkOperationType.valueOf(typeValue.toUpperCase()): null;
    filter = json.getJsonObject("filter");
    document = json.getJsonObject("document");
//Line 57
    upsert = json.getBoolean("upsert");
    multi = json.getBoolean("multi");
    collation = json.getJsonObject("collation") != null ? new CollationOptions(json.getJsonObject("collation")) : null;
  }

Do you have a reproducer?

 new BulkOperation(new JsonObject())
                  .setType(BulkOperationType.INSERT)
                  .setDocument(new JsonObject())
vietj commented 2 years ago

@matter-it-does can you contribute a PR to fix that please ?

matter-it-does commented 2 years ago

done @vietj