Skip to content

Fix NPE when routing on a graph without transit data. - #3804

Merged
hannesj merged 1 commit into
opentripplanner:dev-2.xfrom
dekarl:fix-NPE-without-transit-data
Jan 11, 2022
Merged

hannesj merged 1 commit into
opentripplanner:dev-2.xfrom
dekarl:fix-NPE-without-transit-data

Conversation

@dekarl

@dekarl dekarl commented Jan 7, 2022

Copy link
Copy Markdown
Contributor

Summary

Allow routing without a transit graph. This patch fixes a null pointer exception when reading the time zone from the (non-existant) transit layer by using the existing helper function in the graph object.

Unit tests

I have tested the change by routing on a graph without transit data.

Code style

Have you followed the suggested code style?

"graph contains no agencies (yet); API request times will be interpreted as GMT." is already emitted, make it true

(cherry picked from commit 795a42a8ca3f36ffdc9dbb5d7d6d73888c392dfa)
@dekarl
dekarl requested a review from a team as a code owner January 7, 2022 15:00
@t2gran t2gran added this to the 2.1 milestone Jan 10, 2022
public RoutingResponse route(RoutingRequest request, Router router) {
try {
var zoneId = graph.getTransitLayer().getTransitDataZoneId();
var zoneId = graph.getTimeZone().toZoneId();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we sure this do not create a new problem if these timezone differ? There should only be one truth/source.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you suggest? Only change the code in case where getTransitLayer returns null? And copy the logic of handling null over for the other case?

Suggested change
var zoneId = graph.getTimeZone().toZoneId();
var zoneId = graph.getTransitLayer() ? graph.getTransitLayer().getTransitDataZoneId() : TimeZone.getTimeZone("GMT");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I will just approve your initial suggestion. I looked at the code now, and I see that we copy the TimeZone from the graph into the TransitLayer, so I think it is ok. This is probably something that I would like to take a second look at, while cleaning up the TransitLayer - and removing all transit data from the graph - we would like to break the OTP into smaller pieces. There should be a transit model, and the global OTP context should have a ref to it and inject it where needed.

@t2gran
t2gran requested a review from hannesj January 11, 2022 10:28
@leonardehrenfried

Copy link
Copy Markdown
Member

Once more, if it's good enough for @t2gran then it's good enough for me.

@hannesj
hannesj merged commit faade14 into opentripplanner:dev-2.x Jan 11, 2022
t2gran pushed a commit that referenced this pull request Jan 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants