Skip to content
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

FakeItEasy - NullRef when using ArgumentValueFormatter concurrently #500

Closed
TimLovellSmith opened this issue Jun 26, 2015 · 2 comments · Fixed by #501
Closed

FakeItEasy - NullRef when using ArgumentValueFormatter concurrently #500

TimLovellSmith opened this issue Jun 26, 2015 · 2 comments · Fixed by #501

Comments

@TimLovellSmith
Copy link

I had a one off failure with xunit 2 which I think is a concurrency bug.

Result Message: System.NullReferenceException : Object reference not set to an instance of an object.
Result StackTrace:  
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
   at FakeItEasy.Core.ArgumentValueFormatter.GetArgumentValueAsString(Object argumentValue) in c:\repo\FakeItEasy\Source\FakeItEasy\Core\ArgumentValueFormatter.cs:line 37
   at FakeItEasy.Core.DefaultFakeObjectCallFormatter.GetArgumentValueAsString(Object argumentValue) in c:\repo\FakeItEasy\Source\FakeItEasy\Core\DefaultFakeObjectCallFormatter.cs:line 170
   at FakeItEasy.Core.DefaultFakeObjectCallFormatter.AppendArgumentValue(StringBuilder builder, ArgumentValueInfo argument) in c:\repo\FakeItEasy\Source\FakeItEasy\Core\DefaultFakeObjectCallFormatter.cs:line 162
   at FakeItEasy.Core.DefaultFakeObjectCallFormatter.AppendArguments(StringBuilder builder, IEnumerable`1 arguments) in c:\repo\FakeItEasy\Source\FakeItEasy\Core\DefaultFakeObjectCallFormatter.cs:line 180
   at FakeItEasy.Core.DefaultFakeObjectCallFormatter.AppendArgumentsList(StringBuilder builder, IFakeObjectCall call) in c:\repo\FakeItEasy\Source\FakeItEasy\Core\DefaultFakeObjectCallFormatter.cs:line 148
   at FakeItEasy.Core.DefaultFakeObjectCallFormatter.GetDescription(IFakeObjectCall call) in c:\repo\FakeItEasy\Source\FakeItEasy\Core\DefaultFakeObjectCallFormatter.cs:line 40
   at FakeItEasy.Core.CallWriter.WriteCalls(IEnumerable`1 calls, IOutputWriter writer) in c:\repo\FakeItEasy\Source\FakeItEasy\Core\CallWriter.cs:line 40
   at FakeItEasy.Core.FakeAsserter.AppendCallList(IEnumerable`1 calls, CallWriter callWriter, IOutputWriter writer) in c:\repo\FakeItEasy\Source\FakeItEasy\Core\FakeAsserter.cs:line 86
   at FakeItEasy.Core.FakeAsserter.CreateExceptionMessage(IEnumerable`1 calls, CallWriter callWriter, String callDescription, String repeatDescription, Int32 matchedCallCount) in c:\repo\FakeItEasy\Source\FakeItEasy\Core\FakeAsserter.cs:line 46
   at FakeItEasy.Core.FakeAsserter.AssertWasCalled(Func`2 callPredicate, String callDescription, Func`2 repeatPredicate, String repeatDescription) in c:\repo\FakeItEasy\Source\FakeItEasy\Core\FakeAsserter.cs:line 31
   at FakeItEasy.Configuration.RuleBuilder.MustHaveHappened(Repeated repeatConstraint) in c:\repo\FakeItEasy\Source\FakeItEasy\Configuration\RuleBuilder.cs:line 114
   at FakeItEasy.Configuration.RuleBuilder.ReturnValueConfiguration`1.MustHaveHappened(Repeated repeatConstraint) in c:\repo\FakeItEasy\Source\FakeItEasy\Configuration\RuleBuilder.cs:line 168
   at FakeItEasy.AssertConfigurationExtensions.MustHaveHappened(IAssertConfiguration configuration) in c:\repo\FakeItEasy\Source\FakeItEasy\AssertConfigurationExtensions.cs:line 18
   at [testcode]

The only reason I can think of this can nullref, given the FakeItEasy source I compiled from is that it's a plain Dictionary<> being shared across threads without locking, since it appears ArgumentFormatter is a singleton.

Sending a PR for this soon!

@blairconrad
Copy link
Member

Edited the description to improve formatting.

@blairconrad
Copy link
Member

@TimLovellSmith, thanks very much for your work on this issue. Look for your name in the release notes. 🏆

This issue has been fixed in release 2.0.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants