Skip to content

Commit

Permalink
Merge pull request #806 from akarnokd/ZipNull
Browse files Browse the repository at this point in the history
Fix Zip(IEnumerable) NullReferenceException if a source completes immediately
  • Loading branch information
danielcweber authored Aug 22, 2018
2 parents 73b809e + 1b19cb6 commit 1c4a708
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
6 changes: 5 additions & 1 deletion Rx.NET/Source/src/System.Reactive/Linq/Observable/Zip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,11 @@ private void OnCompleted(int index)
}
else
{
_subscriptions[index].Dispose();
var subscriptions = Volatile.Read(ref _subscriptions);
if (subscriptions != null && subscriptions != Array.Empty<IDisposable>())
{
Disposable.TryDispose(ref subscriptions[index]);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4448,6 +4448,41 @@ public void Zip_AtLeastOneThrows4()

#endregion

[Fact]
public void Zip2WithImmediateReturn()
{
Observable.Zip<Unit, Unit, Unit>(
Observable.Return(Unit.Default),
Observable.Return(Unit.Default),
(_, __) => Unit.Default
)
.Subscribe(_ => { });
}

[Fact]
public void Zip3WithImmediateReturn()
{
Observable.Zip<Unit, Unit, Unit, Unit>(
Observable.Return(Unit.Default),
Observable.Return(Unit.Default),
Observable.Return(Unit.Default),
(_, __, ___) => Unit.Default
)
.Subscribe(_ => { });
}

[Fact]
public void ZipEnumerableWithImmediateReturn()
{
Enumerable.Range(0, 100)
.Select(_ => Observable.Return(Unit.Default))
.Zip()
.Subscribe(_ =>
{
}
);
}
}
#pragma warning restore IDE0039 // Use local function
}

0 comments on commit 1c4a708

Please sign in to comment.