poiati/gmongo — Issue #10: NPE when casting Map to BasicDBObject in find
Author: bluesliverx
Created: 2012-01-30 23:00:40+00:00
State: open

When performing a find using Grails integration with mongo DB plugin, we are converting a map to a basic DB object using code similar to:

```groovy
DomainClass.collection.find([name:"..."] as BasicDBObject)
```

This appears to be going through the Patcher.groovy file in gmongo, which is having a null exception when one or some of the property values are null in the map to be converted. This seems to trace to line 114 of Patcher, where the class of each "argument" is retrieved. Output from an integration test:

```groovy
N/A
java.lang.NullPointerException
at com.gmongo.internal.Patcher._types(Patcher.groovy:114)
at com.gmongo.internal.Patcher._patchInternal_closure1(Patcher.groovy:33)
at com.ace.mws.reports.Something.execute(Something.groovy:33)
at com.ace.mws.reports.SomethingIntegrationSpec.Feature here(SomethingIntegrationSpec.groovy:22)
```

I'm not sure of the args property in the patcher, but can we use a null-safe groovy operator here to prevent problems? We are on grails 1.3.7 which means we use gmongo 0.9.1 as far as I can tell.

I'll submit a pull request, and let me know what you think. Thanks, Brian