Skip to content

Commit

Permalink
fix: NPE in PagingService
Browse files Browse the repository at this point in the history
  • Loading branch information
t2gran committed Dec 13, 2023
1 parent 9b45959 commit 8ff4987
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions src/main/java/org/opentripplanner/service/paging/PagingService.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,15 @@ public PagingService(
List<Itinerary> itineraries
) {
this.searchWindowUsed = searchWindowUsed;
// EDT is required if search-window is set
this.earliestDepartureTime =
searchWindowUsed == null
? earliestDepartureTime
: Objects.requireNonNull(earliestDepartureTime);
this.earliestDepartureTime = earliestDepartureTime;
this.latestArrivalTime = latestArrivalTime;
this.itinerariesSortOrder = Objects.requireNonNull(itinerariesSortOrder);
this.arriveBy = arriveBy;
this.numberOfItineraries = numberOfItineraries;
this.pageCursor = pageCursor;

this.numItinerariesFilterResults = numItinerariesFilterResults;
this.itineraries = itineraries;
this.itineraries = Objects.requireNonNull(itineraries);
this.searchWindowAdjuster =
createSearchWindowAdjuster(
pagingSearchWindowAdjustments,
Expand All @@ -77,7 +73,7 @@ public PageCursor previousPageCursor() {

@Nullable
public TripSearchMetadata createTripSearchMetadata() {
if (noTransitSearchPerformed()) {
if (noSuccessfulTransitSearchPerformed()) {
return null;
}

Expand All @@ -97,7 +93,7 @@ public TripSearchMetadata createTripSearchMetadata() {
}

private Duration calculateSearchWindowNextSearch() {
if (noTransitSearchPerformed()) {
if (noSuccessfulTransitSearchPerformed()) {
return null;
}

Expand Down Expand Up @@ -179,7 +175,7 @@ private PageCursorFactory mapIntoPageCursorFactory(@Nullable PageType currentPag
var searchWindowNextSearch = calculateSearchWindowNextSearch();
var factory = new PageCursorFactory(itinerariesSortOrder, searchWindowNextSearch);

if (noTransitSearchPerformed()) {
if (noSuccessfulTransitSearchPerformed()) {
return factory;
}

Expand All @@ -200,16 +196,19 @@ private PageCursorFactory mapIntoPageCursorFactory(@Nullable PageType currentPag
}

private void assertRequestPrerequisites() {
if (noTransitSearchPerformed()) {
if (noSuccessfulTransitSearchPerformed()) {
throw new IllegalStateException("SearchWindow not set");
}
if (earliestDepartureTime == null) {
throw new IllegalStateException("Earliest departure time not set");
}
}

private boolean noTransitSearchPerformed() {
return searchWindowUsed == null;
/**
* Both SW and EDT must be available to compute paging tokens.
*/
private boolean noSuccessfulTransitSearchPerformed() {
return searchWindowUsed == null || earliestDepartureTime == null;
}

@Override
Expand Down

0 comments on commit 8ff4987

Please sign in to comment.