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,026 | Comments: 44,842

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.


No future posts left, oh my!


  1. Technical observations from my wife (3):
    13 Nov 2015 - Production issues
  2. Production postmortem (13):
    13 Nov 2015 - The case of the “it is slow on that machine (only)”
  3. Speaking (5):
    09 Nov 2015 - Community talk in Kiev, Ukraine–What does it take to be a good developer
  4. Find the bug (5):
    11 Sep 2015 - The concurrent memory buster
  5. Buffer allocation strategies (3):
    09 Sep 2015 - Bad usage patterns
View all series


Main feed Feed Stats
Comments feed   Comments Feed Stats