Permalink
Browse files

Fixing issues with how multi load can now return nulls

  • Loading branch information...
ayende committed Jan 30, 2012
1 parent 85bf5d7 commit 47a72930888dab02a9af4f094b8d1b1613e933d9
@@ -27,22 +27,31 @@ public static class SerializationHelper
///</summary>
public static IEnumerable<JsonDocument> RavenJObjectsToJsonDocuments(IEnumerable<RavenJObject> responses)
{
- return (from doc in responses
- let metadata = doc["@metadata"] as RavenJObject
- let _ = doc.Remove("@metadata")
- let key = Extract(metadata, "@id", string.Empty)
- let lastModified = Extract(metadata, Constants.LastModified, SystemTime.Now, (string d) => ConvertToUtcDate(d))
- let etag = Extract(metadata, "@etag", Guid.Empty, (string g) => new Guid(g))
- let nai = Extract(metadata, "Non-Authoritative-Information", false, (string b) => Convert.ToBoolean(b))
- select new JsonDocument
+ var list = new List<JsonDocument>();
+ foreach (var doc in responses)
+ {
+ if(doc == null)
@cubanx

cubanx Feb 8, 2012

@ayende Now that null can be in the return collection, this line:

results.Any(x => x.NonAuthoritiveInformation ?? false) &&

..can throw a NRE. We have this happening in our current codebase.

I can provide a test case that shows this if need be.

@ayende

ayende via email Feb 8, 2012

Owner
@cubanx

cubanx Feb 8, 2012

Excellent, thanks for the quick turn around.

@cubanx

cubanx Feb 8, 2012

Any idea on when/what build this will be in?

@ghost

ghost via email Feb 8, 2012

Collaborator
+ {
+ list.Add(null);
+ continue;
+ }
+ var metadata = (RavenJObject)doc["@metadata"];
+ doc.Remove("@metadata");
+ var key = Extract(metadata, "@id", string.Empty);
+ var lastModified = Extract(metadata, Constants.LastModified, SystemTime.Now, (string d) => ConvertToUtcDate(d));
+ var etag = Extract(metadata, "@etag", Guid.Empty, (string g) => new Guid(g));
+ var nai = Extract(metadata, "Non-Authoritative-Information", false, (string b) => Convert.ToBoolean(b));
+ list.Add(new JsonDocument
{
Key = key,
LastModified = lastModified,
Etag = etag,
NonAuthoritativeInformation = nai,
Metadata = metadata.FilterHeaders(isServerDocument: false),
DataAsJson = doc,
- }).ToList();
+ });
+ }
+ return list;
}
///<summary>
@@ -74,7 +74,7 @@ public T[] Complete<T>()
}
return results
- .Select(sessionOperations.TrackEntity<T>)
+ .Select(document => document == null ? default(T) : sessionOperations.TrackEntity<T>(document))
.ToArray();
}
}

0 comments on commit 47a7293

Please sign in to comment.