-
Notifications
You must be signed in to change notification settings - Fork 748
Is.Ordered.By() with a field throws NullReferenceException #2292
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I agree. NullReferenceException should never be thrown in any NUnit framework method. |
Wait, I guess we have the design question of whether to support public fields in |
I was already looking at this answering the related StackOverflow question, so I may as well fix it. |
I'm in favor of a better error message. The way to get it is to stop letting exceptions get out of the framework. That will solve a lot of other problems. I'm not in favor of adding fields as an option. There are a number of other features that limit you to properties and wouldn't want to start on a slippery slope. |
If we fix this one, I'm not sure that will impact any of the rest of NUnit's potential bare errors. Seems like a separate review effort. The reason I'm slightly in favor of that slope is that it fits the C# and VB.NET mental model of “a value I can refer to by writing |
@jnm2 Well, it depends how you fix it. All errors that escape can be captured at a single point and reported as some kind of internal framework error by the runner. That would be helpful in telling users that the error is in the framework and should give a stacktrace that we can use to fix it. At some point, we have to say - let's leave the error in and fix the reporting first. Alternatively, you could inject a failure in a private copy of the framework and see how well you can catch and report it. The |
So, only catching bare errors thrown during calculation of a constraint. That sounds good.
To which we can say no if it's a genuinely bad idea. 😄 |
I am just going to switch this to throwing an |
Actually no. Some constraints execute user delegates and which could NRE, making it look like the Framework NRE'd. It's a matter of widespread whitelisting or widespread blacklisting. 😄 |
Any code a user executes in a test, including constructing constraints and asserting on them, generates a result, not an exception. That is, the code may throw, but it's captured and packaged as a result. If an exception escapes, it's one of two things:
Both of those things are errors in the framework. |
Okay. So we already have the whitelisting going. I should have known that from my |
The following code throws a
NullReferenceException
becauseName
is a field, not a property, This is unintuitive for users, so we should probably handle public fields. At the very least, we should give a better error message.The text was updated successfully, but these errors were encountered: