Invalid message about NotNull assignment? Follow
Why am I getting this message about possible null assignment on NotNull property? See the attachment.
VS2012, R# 7.1, .NET 3.5 project
Attachment(s):
Untitled.png
Please sign in to leave a comment.
Why am I getting this message about possible null assignment on NotNull property? See the attachment.
VS2012, R# 7.1, .NET 3.5 project
Please sign in to leave a comment.
Hi Martin,
I would appreciate if you could provide a full code sample, which will demonstrate this. It's hard to say if it's bug or not without knowing the context.
Thank you.
Just paste this into empty Console project:
private static readonly Dictionary<String, IList<MethodInfo>> subscriberLookup = new Dictionary<String, IList<MethodInfo>>();
private static void LogSubscriberLookupDictionary()
{
StringBuilder sb = new StringBuilder();
foreach (KeyValuePair<string, IList<MethodInfo>> pair in subscriberLookup)
{
// gather the method names
string[] methodNames = pair.Value.Select(m => m.ToString()).ToArray();
// append the key and chained method names
sb.AppendFormat("key: {0}, methods: {1}\n", pair.Key, pair.Value != null ? string.Join(";", methodNames) : string.Empty);
}
}
Note the message probably belongs to the string.Join, where the input should not be Null, but why it's shown on pair.Value?
Hi Martin,
Thanks for that! I've logged this issue in YouTrack here: http://youtrack.jetbrains.com/issue/RSRP-336558.
Thank you for your report.
I don't think the warning is invalid - pair.Value is an IList<T>, which could easliy be null. Passing a null list to the Select method will result in an ArgumentNullException.
You should also get a warning on the m.ToString(), since MethodInfo is also a class. If the list contains a null element, you'll get a NullReferenceException.