Ayende @ Rahien

My name is Oren Eini
Founder of Hibernating Rhinos LTD and RavenDB.
You can reach me by phone or email:


+972 52-548-6969

, @ Q c

Posts: 6,128 | Comments: 45,550

filter by tags archive

If stupidity was money, I would be rich

time to read 2 min | 229 words

Here is a crash report that I got from NH Prof error reporting:

System.NullReferenceException: Object reference not set to an instance of an object.
  at HibernatingRhinos.NHibernate.Profiler.Client.Model.Sessions.RecentStatements.set_SelectedStatement(IStatementModel value)
  at HibernatingRhinos.NHibernate.Profiler.Client.Model.Sessions.RecentStatements.Clear()
  at HibernatingRhinos.NHibernate.Profiler.Client.Model.SessionPresenter.Clear()
  at HibernatingRhinos.NHibernate.Profiler.Client.Model.ApplicationModel.Clear()
  at HibernatingRhinos.NHibernate.Profiler.Client.Commands.Clear.Execute(Object parameter)

This seems to be pretty standard, isn’t it? Let us look at SelectedStatement:


There isn’t a possibility of a null reference exception, even the RaisePropertyChanged is safe from NRE.

So, what was going on? I started dismissing this as a ghost story, but I got several issues of those. Then I remember that I am not the only on working on the profiler (well, that is a lie, I got a ‘someone else updated this file’ when I tried to commit) and updated. Here is the updated version:


And there is was, right on the third line in the set.

Lesson learned? Don’t be stupid, svn update.





Wouldn't the following raise and exception (presuming you're not checking the result to the value returned from the SelectedStatement property in the calling code)?

someObject.SelectedStatement = null; //Property not changed, assuming it was init'ed to null

IStatementModel sm = object.selectedStatement; //Get Property value (which is null)

sm.someCall ;//Use sm without checking for null - NullReferenceException thrown

Peter Morris

Rather than a foreach loop wouldn't it be better to do something like this?



if (selectedValue == value)


if (selectedValue != null)

selectedValue.IsSelected = false;

selectedValue = value;

if (selectedValue != null)

selectedValue.IsSelected = true;



Bill Barry

This was the primary reason I had for switching to a dvcs. Given two machines:

on 1:

commit revision 15


on 2:

update to revision 15


The fact that these two builds are not always the same is mildly unnerving (given svn, cvs or tfs). It also makes bugs like these far harder to find than they should be.

Ayende Rahien


There may be more than one selected statement

Ayende Rahien


The problem was that I didn't update my version of the source, there was no other problem.

I forgot to update and was not running on the same version

Peter Morris

I think moving the selected state up to a containing class would speed things up because it would let you use a HashSet <t instead of looping through all items (which may or may not be selected).

private HashSet <istatementmodel SelectedItems;

public bool IsSelected(IStatementModel item)


return SelectedItems.Contains(item);


pubic void Select(IStatementModel item)




pubic void Deselect(IStatementModel item)




public void SetSingleSelected(IStatementModel item)






Comment preview

Comments have been closed on this topic.


  1. The worker pattern - one day from now

There are posts all the way to May 30, 2016


  1. The design of RavenDB 4.0 (14):
    26 May 2016 - The client side
  2. RavenDB 3.5 whirl wind tour (14):
    25 May 2016 - Got anything to declare, ya smuggler?
  3. Tasks for the new comer (2):
    15 Apr 2016 - Quartz.NET with RavenDB
  4. Code through the looking glass (5):
    18 Mar 2016 - And a linear search to rule them
  5. Find the bug (8):
    29 Feb 2016 - When you can't rely on your own identity
View all series


Main feed Feed Stats
Comments feed   Comments Feed Stats