Skip to content

Router compact legs NPE fix in AStar search. Bug fix on #2449 - #2490

Closed
t2gran wants to merge 2 commits into
opentripplanner:masterfrom
RuterNo:ruter_compact_legs_npe_fix_in_seach
Closed

Router compact legs NPE fix in AStar search. Bug fix on #2449#2490
t2gran wants to merge 2 commits into
opentripplanner:masterfrom
RuterNo:ruter_compact_legs_npe_fix_in_seach

Conversation

@t2gran

@t2gran t2gran commented Aug 29, 2017

Copy link
Copy Markdown
Member

The PR 'Compact legs by reversed search #2449' cased a null pointer exception (npe) in the AStar class as reported by @vesameskanen. Please see the discussion in PR #2449 for details.

The NPE is occuring when the timeout is reached at the initialization point in time, and the runState is set to null:

// Since initial states can be multiple, heuristic cannot depend on the initial state.
// Initializing the bidirectional heuristic is a pretty complicated operation that involves searching through
// the streets around the origin and destination.
runState.heuristic.initialize(runState.options, abortTime);
if (abortTime < Long.MAX_VALUE  && System.currentTimeMillis() > abortTime) {
    LOG.warn("Timeout during initialization of goal direction heuristic.");
    options.rctx.debugOutput.timedOut = true;
    runState = null; // Search timed out
    return;
}
(AStar.java:120)

Later when the getPathsToTarget()is called, the result is a NPE.

My approach to fix this was to do a check in the getPathsToTarget() method and return an empty list when runState is null.

This is not a robust solution - it enforces the AStar logic to make sure the runState is not null everywhere. Perhaps a better way would be to throw some kind of TimeOutException when a timeout is detected and handle this at an higher level. But, I have to say that with my limited experience with OTP, I am not comfortable to such change. Any comments on this is encouraged.

}

public List<GraphPath> getPathsToTarget() {
if(runState == null) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: space after (

@novalis novalis changed the title Ruter compact legs NPE fix in AStar search. Bug fix on #2449 Router compact legs NPE fix in AStar search. Bug fix on #2449 Sep 12, 2017
@novalis novalis closed this in 7c8be8c Sep 12, 2017
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.

2 participants