From db3adaa104ec69502c53cdf72f83568a7478c822 Mon Sep 17 00:00:00 2001 From: John Cummings Date: Thu, 23 Jul 2020 11:59:42 -0500 Subject: [PATCH 1/2] fix: avoid throwing ArgumentNullException from OAPH.Value (#2455) Ensure OAPH CompositeDisposable is not null before subscribing Add unit test to cover case where OAPH has been disposed --- .../ObservableAsPropertyHelperTest.cs | 19 +++++++++++++++++++ .../ObservableAsPropertyHelper.cs | 7 ++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/ReactiveUI.Tests/ObservableAsPropertyHelper/ObservableAsPropertyHelperTest.cs b/src/ReactiveUI.Tests/ObservableAsPropertyHelper/ObservableAsPropertyHelperTest.cs index 205aa59951..d5074c94d7 100644 --- a/src/ReactiveUI.Tests/ObservableAsPropertyHelper/ObservableAsPropertyHelperTest.cs +++ b/src/ReactiveUI.Tests/ObservableAsPropertyHelper/ObservableAsPropertyHelperTest.cs @@ -162,6 +162,25 @@ public void OAPHDeferSubscriptionParameterIsSubscribedIsNotTrueInitially() Assert.True(fixture.IsSubscribed); } + [Fact] + public void OAPHDeferSubscriptionShouldNotThrowIfDisposed() + { + var observable = Observable.Create(o => + { + o.OnNext(42); + o.OnCompleted(); + + return Disposable.Empty; + }); + + var fixture = new ObservableAsPropertyHelper(observable, _ => { }, 0, true); + + Assert.False(fixture.IsSubscribed); + fixture.Dispose(); + var ex = Record.Exception(() => Assert.Equal(0, fixture.Value)); + Assert.Null(ex); + } + [Fact] public void OAPHShouldRethrowErrors() { diff --git a/src/ReactiveUI/ObservableForProperty/ObservableAsPropertyHelper.cs b/src/ReactiveUI/ObservableForProperty/ObservableAsPropertyHelper.cs index 277dadb3cd..d426d9f0f0 100644 --- a/src/ReactiveUI/ObservableForProperty/ObservableAsPropertyHelper.cs +++ b/src/ReactiveUI/ObservableForProperty/ObservableAsPropertyHelper.cs @@ -136,7 +136,12 @@ public T Value { if (Interlocked.CompareExchange(ref _activated, 1, 0) == 0) { - _source.Subscribe(_subject).DisposeWith(_disposable); + // Do not subscribe if disposed + var localReferenceInCaseDisposeIsCalled = _disposable; + if (localReferenceInCaseDisposeIsCalled != null) + { + _source.Subscribe(_subject).DisposeWith(localReferenceInCaseDisposeIsCalled); + } } return _lastValue; From e2bffe9a89d3f79157e3e8405a0d3b2e8597b9fe Mon Sep 17 00:00:00 2001 From: John Cummings Date: Thu, 23 Jul 2020 12:08:03 -0500 Subject: [PATCH 2/2] docs: remove duplicate words in OAPH documentation --- .../ObservableForProperty/ObservableAsPropertyHelper.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ReactiveUI/ObservableForProperty/ObservableAsPropertyHelper.cs b/src/ReactiveUI/ObservableForProperty/ObservableAsPropertyHelper.cs index d426d9f0f0..cbf0c4515b 100644 --- a/src/ReactiveUI/ObservableForProperty/ObservableAsPropertyHelper.cs +++ b/src/ReactiveUI/ObservableForProperty/ObservableAsPropertyHelper.cs @@ -48,7 +48,7 @@ public sealed class ObservableAsPropertyHelper : IHandleObservableErrors, IDi /// A value indicating whether the /// should defer the subscription to the source /// until the first call to , or if it should immediately - /// subscribe to the the source. + /// subscribe to the source. /// /// /// The scheduler that the notifications will be provided on - @@ -85,7 +85,7 @@ public ObservableAsPropertyHelper( /// A value indicating whether the /// should defer the subscription to the source /// until the first call to , or if it should immediately - /// subscribe to the the source. + /// subscribe to the source. /// /// /// The scheduler that the notifications will provided on - this