string.IsNullOrEmpty() causes Index to fail

215 views
Skip to first unread message

Paul

unread,
Nov 12, 2012, 5:16:57 AM11/12/12
to rav...@googlegroups.com

We have updated to RavenDB 1.2.2137 (from 1.2.2084) and have had an index fail unexpectedly.

We traced it down to the usage of string.IsNullOrEmpty() in a specific case.

 

Having replaced the usage of

string.IsNullOrEmpty(c.PropertyName)

with

“c.PropertyName == null || c.PropertyName.Trim().Length == 0,

the index works again.

 

We have failing tests, but a fail test could not reproduce the situation outside of our current context.

Concrete the lines of code, which had to be replaced, can be seen below.

 

Does anybody have an idea what could cause such behaviour?

 

class ContactDto_Index : AbstractIndexCreationTask<ContactDto, ContactDto_Index.Result>

{

          public class Result

       {

               

                                       public string LegalEntityNameOrder { get; set; }

                public bool HasLabel { get; set; }

                                       

}

Map = content => from c in content

                select new

                {

                                                                                               

Broken:

//LegalEntityNameOrder = string.IsNullOrEmpty(c.LegalEntityName) ? "zzzzzzz" : c.LegalEntityName,

Works:

LegalEntityNameOrder = c.LegalEntityName == null || c.LegalEntityName.Trim().Length == 0 ? "zzzzzzz" : c.LegalEntityName,

 

Did not need change:

HasLabel =  !string.IsNullOrEmpty(string.Join("", c.LegalEntityName, c.SurName, c.FirstName, c.SecondName).Trim())

 

}

Index(x => x.LegalEntityNameOrder, FieldIndexing.Analyzed);

Sort(x => x.LegalEntityNameOrder, SortOptions.String);

Analyzers.Add(x => x.LegalEntityNameOrder, currentCollationAnalyzer);

}

Barry

unread,
Nov 12, 2012, 10:19:03 AM11/12/12
to rav...@googlegroups.com
We saw the same thing after moving from 2134 to 2137 through 2140.  In our case it was the transform on an index that used string.IsNullOrWhiteSpace().  If the value being checked was null, it threw this:

System.InvalidOperationException: The transform results function failed.
Doc 'documents/22', Error: The best overloaded method match for 'string.IsNullOrWhiteSpace(string)' has some invalid arguments
   at Raven.Database.DocumentDatabase.<>c__DisplayClass95.<Query>b__8b(IStorageActionsAccessor actions) in c:\\Builds\\RavenDB-Unstable-v1.2\\Raven.Database\\DocumentDatabase.cs:line 992
   at Raven.Storage.Esent.TransactionalStorage.ExecuteBatch(Action`1 action) in c:\\Builds\\RavenDB-Unstable-v1.2\\Raven.Database\\Storage\\Esent\\TransactionalStorage.cs:line 481
   at Raven.Storage.Esent.TransactionalStorage.Batch(Action`1 action) in c:\\Builds\\RavenDB-Unstable-v1.2\\Raven.Database\\Storage\\Esent\\TransactionalStorage.cs:line 439
   at Raven.Database.DocumentDatabase.Query(String index, IndexQuery query) in c:\\Builds\\RavenDB-Unstable-v1.2\\Raven.Database\\DocumentDatabase.cs:line 1051
   at Raven.Database.Server.Responders.Index.PerformQueryAgainstExistingIndex(IHttpContext context, String index, IndexQuery indexQuery, Guid& indexEtag) in c:\\Builds\\RavenDB-Unstable-v1.2\\Raven.Database\\Server\\Responders\\Index.cs:line 448
   at Raven.Database.Server.Responders.Index.ExecuteQuery(IHttpContext context, String index, Guid& indexEtag) in c:\\Builds\\RavenDB-Unstable-v1.2\\Raven.Database\\Server\\Responders\\Index.cs:line 385
   at Raven.Database.Server.Responders.Index.GetIndexQueryRessult(IHttpContext context, String index) in c:\\Builds\\RavenDB-Unstable-v1.2\\Raven.Database\\Server\\Responders\\Index.cs:line 324
   at Raven.Database.Server.HttpServer.DispatchRequest(IHttpContext ctx) in c:\\Builds\\RavenDB-Unstable-v1.2\\Raven.Database\\Server\\HttpServer.cs:line 803
   at Raven.Database.Server.HttpServer.HandleActualRequest(IHttpContext ctx) in c:\\Builds\\RavenDB-Unstable-v1.2\\Raven.Database\\Server\\HttpServer.cs:line 548


So I believe it is only null values that cause the issue.  You will never get a null in your HasLabel line, so that is why no change was needed there.

Oren Eini (Ayende Rahien)

unread,
Nov 12, 2012, 10:33:45 AM11/12/12
to rav...@googlegroups.com
Fixed
Reply all
Reply to author
Forward
0 new messages