ReactiveCouchbase / ReactiveCouchbase-core

Core library for ReactiveCouchbase
Apache License 2.0
64 stars 28 forks source link

Null Pointer Exception on Find queries when Couchbase returns a null document #52

Closed pcboy closed 8 years ago

pcboy commented 9 years ago

There seem to be a bug here:
https://github.com/ReactiveCouchbase/ReactiveCouchbase-core/blob/master/driver/src/main/scala/org/reactivecouchbase/client/Queries.scala#L226

  def search[T](view: View)(query: Query)(implicit bucket: CouchbaseBucket, r: Reads[T], ec: ExecutionContext): QueryEnumerator[TypedRow[T]] = {
    QueryEnumerator(() => rawSearch(view)(query)(bucket, ec).toEnumerator.map { enumerator =>
      enumerator &>
        Enumeratee.map[RawRow] { row =>
          row.document.map { doc =>
            JsRow[T](r.reads(Json.parse(doc)), row.id, row.key, row.value)
          }.getOrElse(
            JsRow[T](JsError(), row.id, row.key, row.value)
          )
        } &>
        Enumeratee.collect[JsRow[T]] {
          case JsRow(JsSuccess(doc, _), id, key, value) => TypedRow[T](doc, id, key, value)
          case JsRow(JsError(errors), _, _, _) if bucket.jsonStrictValidation => throw new JsonValidationException("Invalid JSON content", JsError.toFlatJson(errors))
        }
    })
  }

Sometimes my Couchbase server returns me a RawRow with a Some(null) as document. It happens sometimes during stress testing (not sure why yet, but it seems it can happen).

So of course Json.parse(null) fails and throw a Null Pointer Exception. Checking if doc is null fixes the issue. Seems like this should be done.

mathieuancelin commented 9 years ago

That's weird ... but I will fix it.

Thanks