These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Dictionary usage bug in NHibernate.Cfg.Configuration.Mapping
PostPosted: Wed Feb 04, 2009 5:06 am 
Newbie

Joined: Tue Jan 20, 2009 9:54 am
Posts: 2
There's a bug in NHibernate.Cfg.Configuration.Mapping.GetPersistentClass(string className) caused by incorrect Dictionary usage. If you have forgot to map a class, you would normally get a MappingException describing which class is unmapped. From this particular class, however, you get a KeyNotFoundException.

The current source code is:

Code:
PersistentClass pc = configuration.classes[className];
if (pc == null)
{
   throw new MappingException("persistent class not known: " + className);
}
return pc;


However, a Dictionary will not return null if a key does not exist. You will get a KeyNotFoundException instead. The safe way of using IDictionary is:

Code:
if (!configuration.classes.ContainsKey(className))
{
   throw new MappingException("persistent class not known: " + className);
}

return configuration.classes[className];


I've checked out the source code, made this change, and verified that it does in fact throw MappingException instead of the KeyNotFoundException I was getting earlier.

I've also seen that this bug was reported on the forum way back in 2006, but apparently not taken care of. jira.nhibernate.org is unreachable, as always, so I'm unable to search it for relevant issues.

Any opinion on why this hasn't been picked up earlier?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.