[JAVA-2019] MongoCollection.aggregate() throws NullPointerException when no batchSize is specified Created: 22/Oct/15  Updated: 12/Nov/15  Resolved: 23/Oct/15

Status: Closed
Project: Java Driver
Component/s: Query Operations
Affects Version/s: 3.0.4
Fix Version/s: 3.1.1, 3.2.0

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

Java 7
MongoDB server version 3.0.x



 Description   

When executing an aggregate pipeline, the Java driver gives me a NullPointerException without further explanation.

While debugging I found that it's happening while trying to unbox AggregateIterableImpl.batchSize of type java.lang.Integer to be written to field FindIterableImpl.findOptions.batchSize of type int.

When I specify a batchSize() at the Aggregate other than null, e.g. explicitly setting it to "0" (the documented default value), everything is fine.

So, instead of just using

List<Document> result = collection.aggregate(pipeline).into(new LinkedList<Document>);

I need to write

List<Document> result = collection.aggregate(pipeline).batchSize(0).into(new LinkedList<Document>);

which is rather unusual and smells a bit bad .

I think it would help to change the type of the batchSize attribute of AggregateIterableImpl from java.lang.Integer to int, but I cannot tell whether it has any side-effects...



 Comments   
Comment by Jeffrey Yemin [ 12/Nov/15 ]

Closing for 3.1.1 release.

Comment by Githook User [ 23/Oct/15 ]

Author:

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

Message: Fix NPE bug in AggregateIterable

JAVA-2019
Branch: 3.1.x
https://github.com/mongodb/mongo-java-driver/commit/cd8442593b902464dd0e0f69e1fa912acff4cb0d

Comment by Githook User [ 23/Oct/15 ]

Author:

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

Message: Fix NPE bug in AggregateIterable

JAVA-2019
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/75fd3659d4b0c2fb743347217c75227ef8738e8e

Comment by Jeffrey Yemin [ 22/Oct/15 ]

OK, that's what I thought. The $out stage is the trigger for this bug. Thanks for the report, and it's good to know that you have a workaround until we get this fixed.

Comment by Rene Zanner [ 22/Oct/15 ]

Yes - actually, it's the only stage in my pipeline... I use it to clone my collection.

Comment by Jeffrey Yemin [ 22/Oct/15 ]

Hi Rene,

Can you confirm whether the last stage of the pipeline is a $out?

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