Ayende @ Rahien

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

ayende@ayende.com

+972 52-548-6969

, @ Q c

Posts: 18 | Comments: 72

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:

image

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:

image

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

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


Comments

Rob
Rob

Oops...

anon

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?

set

{

if (selectedValue == value)

return;

if (selectedValue != null)

selectedValue.IsSelected = false;

selectedValue = value;

if (selectedValue != null)

selectedValue.IsSelected = true;

RaisePropertyChanged("SelectedValue");

}

Bill Barry

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

on 1:

commit revision 15

build

on 2:

update to revision 15

build

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

Peter,

There may be more than one selected statement

Ayende Rahien

Bill,

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)

{

SelectedItems.Add(item);

}

pubic void Deselect(IStatementModel item)

{

SelectedItems.Remove(item);

}

public void SetSingleSelected(IStatementModel item)

{

SelectedItems.Clear();

Select(item);

}

Pete

Comment preview

Comments have been closed on this topic.

FUTURE POSTS

  1. RavenDB 3.0 New Stable Release - 7 hours from now
  2. Production postmortem: The industry at large - about one day from now
  3. The insidious cost of allocations - 2 days from now
  4. Buffer allocation strategies: A possible solution - 5 days from now
  5. Buffer allocation strategies: Explaining the solution - 6 days from now

And 3 more posts are pending...

There are posts all the way to Sep 11, 2015

RECENT SERIES

  1. Find the bug (5):
    20 Apr 2011 - Why do I get a Null Reference Exception?
  2. Production postmortem (10):
    01 Sep 2015 - The case of the lying configuration file
  3. What is new in RavenDB 3.5 (7):
    12 Aug 2015 - Monitoring support
  4. Career planning (6):
    24 Jul 2015 - The immortal choices aren't
View all series

RECENT COMMENTS

Syndication

Main feed Feed Stats
Comments feed   Comments Feed Stats