From e9d5d3dd509dde428f7bacfdee0232c8ba5b8c33 Mon Sep 17 00:00:00 2001 From: Joel Lappalainen Date: Fri, 17 May 2024 14:16:50 +0300 Subject: [PATCH] Make eq/hc null safe --- .../apis/gtfs/model/PlanPageInfo.java | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/opentripplanner/apis/gtfs/model/PlanPageInfo.java b/src/main/java/org/opentripplanner/apis/gtfs/model/PlanPageInfo.java index 1575933b924..6eebad77580 100644 --- a/src/main/java/org/opentripplanner/apis/gtfs/model/PlanPageInfo.java +++ b/src/main/java/org/opentripplanner/apis/gtfs/model/PlanPageInfo.java @@ -49,8 +49,8 @@ public Duration searchWindowUsed() { @Override public int hashCode() { return Objects.hash( - startCursor.getValue(), - endCursor.getValue(), + startCursor != null ? startCursor.getValue() : null, + endCursor != null ? endCursor.getValue() : null, hasPreviousPage, hasNextPage, searchWindowUsed @@ -67,8 +67,22 @@ public boolean equals(Object o) { } PlanPageInfo that = (PlanPageInfo) o; return ( - Objects.equals(startCursor.getValue(), that.startCursor.getValue()) && - Objects.equals(endCursor.getValue(), that.endCursor.getValue()) && + ( + (startCursor == null && that.startCursor == null) || + ( + startCursor != null && + that.startCursor != null && + Objects.equals(startCursor.getValue(), that.startCursor.getValue()) + ) + ) && + ( + (endCursor == null && that.endCursor == null) || + ( + endCursor != null && + that.endCursor != null && + Objects.equals(endCursor.getValue(), that.endCursor.getValue()) + ) + ) && Objects.equals(searchWindowUsed, that.searchWindowUsed) && hasPreviousPage == that.hasPreviousPage && hasNextPage == that.hasNextPage