Skip to content

Commit

Permalink
Informative error message when reequesting a list of evnets that cont…
Browse files Browse the repository at this point in the history
…ains null (closes #184)
  • Loading branch information
michbarsinai committed Jul 12, 2022
1 parent c3efaee commit f15b469
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ If you use BPjs in an academic work, please consider citing it as:
* :arrow_up: Improved warrping of Java objects as they come to JavaScript: Java strings are now treated as native JS strings, so using the `===` operator works as expected. ([#104](https://github.com/bThink-BGU/BPjs/issues/104)).
* :bug: Verification stops on ECMAScript errors ([#49](https://github.com/bThink-BGU/BPjs/issues/49)).
* :bug: Improved error reporting when trying to sync outside of a b-thread ([#174](https://github.com/bThink-BGU/BPjs/issues/174)).
* :arrow_up: Informative error message when requesting a list of events and one of the events is `null` ([#184](https://github.com/bThink-BGU/BPjs/issues/184)).


### 2022-02 (Including the 1st BP Day Hackathon)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import il.ac.bgu.cs.bp.bpjs.model.eventsets.EventSet;
import il.ac.bgu.cs.bp.bpjs.model.eventsets.EventSets;
import il.ac.bgu.cs.bp.bpjs.model.eventsets.JsEventSet;
import java.util.List;
import org.mozilla.javascript.*;

import java.util.Map;
Expand Down Expand Up @@ -250,9 +251,13 @@ void synchronizationPoint(NativeObject jsRWB, Boolean hot, Object data) {
try {
if (req instanceof NativeArray) {
NativeArray arr = (NativeArray) req;
stmt = stmt.request(arr.getIndexIds().stream()
.map(i -> (BEvent) arr.get(i))
.collect(toList()));
final List<BEvent> requestedEvents = arr.getIndexIds().stream()
.map(i -> (BEvent) arr.get(i))
.collect(toList());
if ( requestedEvents.contains(null) ) {
throw new RuntimeException("Cannot request a null event. B-thread name: "+ CURRENT_BTHREAD.get().snapshot.getName());
}
stmt = stmt.request(requestedEvents);
} else {
stmt = stmt.request((BEvent) req);
}
Expand Down Expand Up @@ -286,7 +291,7 @@ private EventSet convertToEventSet(Object jsObject) {
if (arr.isEmpty()) return EventSets.none;

if (Stream.of(arr.getIds()).anyMatch(id -> arr.get(id) == null)) {
throw new RuntimeException("EventSet Array contains null sets. Exception causing b-thread: "
throw new RuntimeException("EventSet Array contains null sets. B-thread name: "
+ CURRENT_BTHREAD.get().snapshot.getName());
}

Expand Down

0 comments on commit f15b469

Please sign in to comment.