File tree Expand file tree Collapse file tree 1 file changed +8
-1
lines changed
rxjava-core/src/main/java/rx/operators Expand file tree Collapse file tree 1 file changed +8
-1
lines changed Original file line number Diff line number Diff line change @@ -104,6 +104,7 @@ public void remove() {
104
104
private static class NextObserver <T > implements Observer <Notification <? extends T >> {
105
105
private final BlockingQueue <Notification <? extends T >> buf = new ArrayBlockingQueue <Notification <? extends T >>(1 );
106
106
private final AtomicBoolean waiting = new AtomicBoolean (false );
107
+ private volatile boolean completed = false ;
107
108
108
109
@ Override
109
110
public void onCompleted () {
@@ -139,7 +140,11 @@ public void await() {
139
140
public boolean isCompleted (boolean rethrowExceptionIfExists ) {
140
141
Notification <? extends T > lastItem = buf .peek ();
141
142
if (lastItem == null ) {
142
- return false ;
143
+ // Fixed issue #383 testOnErrorViaHasNext fails sometimes.
144
+ // If the buf is empty, there are two cases:
145
+ // 1. The next item has not been emitted yet.
146
+ // 2. The error or completed notification is removed in takeNext method.
147
+ return completed ;
143
148
}
144
149
145
150
if (lastItem .isOnError ()) {
@@ -157,10 +162,12 @@ public T takeNext() throws InterruptedException {
157
162
Notification <? extends T > next = buf .take ();
158
163
159
164
if (next .isOnError ()) {
165
+ completed = true ;
160
166
throw Exceptions .propagate (next .getThrowable ());
161
167
}
162
168
163
169
if (next .isOnCompleted ()) {
170
+ completed = true ;
164
171
throw new IllegalStateException ("Observable is completed" );
165
172
}
166
173
You can’t perform that action at this time.
0 commit comments