Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
RavenDB-1009 SaveChanges() will throw NullReferenceException if chang…
…ing byte[] property from null to value
  • Loading branch information
ayende committed Mar 20, 2013
1 parent 892ff8f commit b9179f1
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Raven.Abstractions/Json/Linq/RavenJToken.cs
Expand Up @@ -314,6 +314,8 @@ internal virtual bool DeepEquals(RavenJToken other)
byte[] tokenBytes = token.Type == JTokenType.String byte[] tokenBytes = token.Type == JTokenType.String
? Convert.FromBase64String(token.Value<string>()) ? Convert.FromBase64String(token.Value<string>())
: token.Value<byte[]>(); : token.Value<byte[]>();
if (tokenBytes == null)
return false;
if (bytes.Length != tokenBytes.Length) if (bytes.Length != tokenBytes.Length)
return false; return false;


Expand Down
38 changes: 38 additions & 0 deletions Raven.Tests/Issues/RavenDB1009.cs
@@ -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();
}
}
}
}
}
1 change: 1 addition & 0 deletions Raven.Tests/Raven.Tests.csproj
Expand Up @@ -523,6 +523,7 @@
<Compile Include="Issues\BulkInsertAuth.cs" /> <Compile Include="Issues\BulkInsertAuth.cs" />
<Compile Include="Issues\BulkInsertClient.cs" /> <Compile Include="Issues\BulkInsertClient.cs" />
<Compile Include="Issues\DatabaseReloadingTests.cs" /> <Compile Include="Issues\DatabaseReloadingTests.cs" />
<Compile Include="Issues\RavenDB1009.cs" />
<Compile Include="Issues\RavenDB815.cs" /> <Compile Include="Issues\RavenDB815.cs" />
<Compile Include="Issues\RavenDB820.cs" /> <Compile Include="Issues\RavenDB820.cs" />
<Compile Include="Issues\RavenDb827.cs" /> <Compile Include="Issues\RavenDb827.cs" />
Expand Down

0 comments on commit b9179f1

Please sign in to comment.