@@ -629,7 +629,7 @@ private class DataLoaderSubscriber implements Subscriber<V> {
629
629
private final List <V > completedValues = new ArrayList <>();
630
630
private int idx = 0 ;
631
631
private boolean onErrorCalled = false ;
632
- private boolean onCompletedCalled = false ;
632
+ private boolean onCompleteCalled = false ;
633
633
634
634
private DataLoaderSubscriber (
635
635
CompletableFuture <List <V >> valuesFuture ,
@@ -650,7 +650,8 @@ public void onSubscribe(Subscription subscription) {
650
650
651
651
@ Override
652
652
public void onNext (V value ) {
653
- assert !onErrorCalled && !onCompletedCalled ;
653
+ assertState (!onErrorCalled , () -> "onError has already been called; onNext may not be invoked." );
654
+ assertState (!onCompleteCalled , () -> "onComplete has already been called; onNext may not be invoked." );
654
655
655
656
K key = keys .get (idx );
656
657
Object callContext = callContexts .get (idx );
@@ -680,8 +681,8 @@ public void onNext(V value) {
680
681
681
682
@ Override
682
683
public void onComplete () {
683
- assert !onErrorCalled ;
684
- onCompletedCalled = true ;
684
+ assertState ( !onErrorCalled , () -> "onError has already been called; onComplete may not be invoked." ) ;
685
+ onCompleteCalled = true ;
685
686
686
687
assertResultSize (keys , completedValues );
687
688
@@ -691,7 +692,7 @@ public void onComplete() {
691
692
692
693
@ Override
693
694
public void onError (Throwable ex ) {
694
- assert ! onCompletedCalled ;
695
+ assertState (! onCompleteCalled , () -> "onComplete has already been called; onError may not be invoked." ) ;
695
696
onErrorCalled = true ;
696
697
697
698
stats .incrementBatchLoadExceptionCount (new IncrementBatchLoadExceptionCountStatisticsContext <>(keys , callContexts ));
@@ -720,7 +721,7 @@ private class DataLoaderMapEntrySubscriber implements Subscriber<Map.Entry<K, V>
720
721
private final List <K > clearCacheKeys = new ArrayList <>();
721
722
private final Map <K , V > completedValuesByKey = new HashMap <>();
722
723
private boolean onErrorCalled = false ;
723
- private boolean onCompletedCalled = false ;
724
+ private boolean onCompleteCalled = false ;
724
725
725
726
private DataLoaderMapEntrySubscriber (
726
727
CompletableFuture <List <V >> valuesFuture ,
@@ -751,7 +752,8 @@ public void onSubscribe(Subscription subscription) {
751
752
752
753
@ Override
753
754
public void onNext (Map .Entry <K , V > entry ) {
754
- assert !onErrorCalled && !onCompletedCalled ;
755
+ assertState (!onErrorCalled , () -> "onError has already been called; onNext may not be invoked." );
756
+ assertState (!onCompleteCalled , () -> "onComplete has already been called; onNext may not be invoked." );
755
757
K key = entry .getKey ();
756
758
V value = entry .getValue ();
757
759
@@ -781,8 +783,8 @@ public void onNext(Map.Entry<K, V> entry) {
781
783
782
784
@ Override
783
785
public void onComplete () {
784
- assert !onErrorCalled ;
785
- onCompletedCalled = true ;
786
+ assertState ( !onErrorCalled , () -> "onError has already been called; onComplete may not be invoked." ) ;
787
+ onCompleteCalled = true ;
786
788
787
789
possiblyClearCacheEntriesOnExceptions (clearCacheKeys );
788
790
List <V > values = new ArrayList <>(keys .size ());
@@ -795,7 +797,7 @@ public void onComplete() {
795
797
796
798
@ Override
797
799
public void onError (Throwable ex ) {
798
- assert ! onCompletedCalled ;
800
+ assertState (! onCompleteCalled , () -> "onComplete has already been called; onError may not be invoked." ) ;
799
801
onErrorCalled = true ;
800
802
801
803
stats .incrementBatchLoadExceptionCount (new IncrementBatchLoadExceptionCountStatisticsContext <>(keys , callContexts ));
0 commit comments