Permalink
Browse files

RavenDB-1009 SaveChanges() will throw NullReferenceException if chang…

…ing byte[] property from null to value
  • Loading branch information...
1 parent 892ff8f commit b9179f12df3136c895565bb4075b894a3a650eef @ayende ayende committed Mar 20, 2013
@@ -314,6 +314,8 @@ internal virtual bool DeepEquals(RavenJToken other)
byte[] tokenBytes = token.Type == JTokenType.String
? Convert.FromBase64String(token.Value<string>())
: token.Value<byte[]>();
+ if (tokenBytes == null)
+ return false;
if (bytes.Length != tokenBytes.Length)
return false;
@@ -0,0 +1,38 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using Xunit;
+
+namespace Raven.Tests.Issues
+{
+ public class RavenDB1009 : RavenTest
+ {
+ class Foo
+ {
+ public byte[] Hash { get; set; }
+ }
+
+ [Fact]
+ public void CanHandleWhenSettingByteArrayToNull()
+ {
+ using (var store = NewDocumentStore())
+ {
+ // store a doc
+ using (var session = store.OpenSession())
+ {
+ session.Store(new Foo(), "foos/1");
+ session.SaveChanges();
+ }
+
+ // store a doc
+ using (var session = store.OpenSession())
+ {
+ var foo = session.Load<Foo>("foos/1");
+ foo.Hash = new byte[100];
+ session.SaveChanges();
+ }
+ }
+ }
+ }
+}
@@ -523,6 +523,7 @@
<Compile Include="Issues\BulkInsertAuth.cs" />
<Compile Include="Issues\BulkInsertClient.cs" />
<Compile Include="Issues\DatabaseReloadingTests.cs" />
+ <Compile Include="Issues\RavenDB1009.cs" />
<Compile Include="Issues\RavenDB815.cs" />
<Compile Include="Issues\RavenDB820.cs" />
<Compile Include="Issues\RavenDb827.cs" />

0 comments on commit b9179f1

Please sign in to comment.