Skip to content

Conversation

@t2gran
Copy link
Member

@t2gran t2gran commented Feb 11, 2025

Summary

In some cases Raptor instrument access and egress by decorating the instance passed in by the OTP application. The result path returned by raptor will include these instrumented paths. The itinerary mapper assume the all access and egress legs returned from Raptor are of the original type RoutingAccessEgress - this fails:

RoutingAccessEgress accessPath = (RoutingAccessEgress) accessPathLeg.access();

RoutingAccessEgress egressPath = (RoutingAccessEgress) egressPathLeg.egress();

This PR fixes this.

Several test failed after I fixed the bug in the RaptorPathToItineraryMapper. The test are known to NOT use proper test data. Instead of using the OTP domain classes they uses the Raptor Test Mockups (copied over into the application when moving Raptor out). I went through the mocks and deleted all unused code - I wanted to reduse the amount of code I needed to fix. Then, I fixed the mockup to use the OTP Domain objects (DefaultAccessEgress) for access and egress. I did NOT swap out the timetable data, since fixing the access/egress was enough to make the test green again.

At Entur we have seen this in via vistit seach, but it is probably not limited to this.

Issue

🟥 There in no issue reported for this.

This query can be used to reproduce the error:

{
  trip(
    from: {
      name: "Stabekk stasjon"
      place: "NSR:StopPlace:59654"
    },
    to: {
      name: "Lillestrøm stasjon"
      place: "NSR:StopPlace:62339"
    },
    numTripPatterns: 3,
    dateTime: "2025-02-12T10:36:41.763+01:00",
    walkSpeed: 1.3,
    arriveBy: false,
    via: {
      visit: {
        label: "Lysaker"
        minimumWaitTime: "PT120S"
        stopLocationIds: ["NSR:StopPlace:58856"]
      }
    }
  ) {
    tripPatterns {
      expectedStartTime
      duration
      walkDistance
      legs {
        mode
        fromPlace {
          name
        }
        toPlace {
          name
        }
        distance
        line {
          id
          publicCode
        }
      }
    }
  }
}

And this is one of the log events from the logs ():

Exception while fetching data (/trip) : class org.opentripplanner.raptor.api.model.AbstractAccessEgressDecorator$1 cannot be cast to class org.opentripplanner.routing.algorithm.raptoradapter.transit.RoutingAccessEgress (org.opentripplanner.raptor.api.model.AbstractAccessEgressDecorator$1 and org.opentripplanner.routing.algorithm.raptoradapter.transit.RoutingAccessEgress are in unnamed module of loader 'app')
java.lang.ClassCastException: class org.opentripplanner.raptor.api.model.AbstractAccessEgressDecorator$1 cannot be cast to class org.opentripplanner.routing.algorithm.raptoradapter.transit.RoutingAccessEgress (org.opentripplanner.raptor.api.model.AbstractAccessEgressDecorator$1 and org.opentripplanner.routing.algorithm.raptoradapter.transit.RoutingAccessEgress are in unnamed module of loader 'app')
	at org.opentripplanner.routing.algorithm.mapping.RaptorPathToItineraryMapper.mapAccessLeg(RaptorPathToItineraryMapper.java:194)
	at org.opentripplanner.routing.algorithm.mapping.RaptorPathToItineraryMapper.createItinerary(RaptorPathToItineraryMapper.java:103)
	:
	at org.opentripplanner.routing.algorithm.raptoradapter.router.TransitRouter.route(TransitRouter.java:183)
	at org.opentripplanner.routing.algorithm.raptoradapter.router.TransitRouter.routeAndCleanupAfter(TransitRouter.java:106)
	at org.opentripplanner.routing.algorithm.raptoradapter.router.TransitRouter.route(TransitRouter.java:99)
	at org.opentripplanner.routing.algorithm.RoutingWorker.routeTransit(RoutingWorker.java:278)
	at org.opentripplanner.routing.algorithm.RoutingWorker.route(RoutingWorker.java:131)
	at org.opentripplanner.routing.service.DefaultRoutingService.route(DefaultRoutingService.java:43)
	at org.opentripplanner.apis.transmodel.TransmodelGraphQLPlanner.plan(TransmodelGraphQLPlanner.java:32)
	at org.opentripplanner.apis.transmodel.model.plan.TripQuery.lambda$create$0(TripQuery.java:652)
	at graphql.execution.ExecutionStrategy.invokeDataFetcher(ExecutionStrategy.java:533)
	:
	at graphql.GraphQL.execute(GraphQL.java:359)
	at org.opentripplanner.apis.transmodel.TransmodelGraph.executeGraphQL(TransmodelGraph.java:68)
	at org.opentripplanner.apis.transmodel.TransmodelAPI.getGraphQL(TransmodelAPI.java:132)
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)

Unit tests

✅ A few new unit tests are added, but no regression test for the mapper.

Documentation

🟥 Only code comments are updated.

Changelog

This is should be listed under minor bugfixes.

Bumping the serialization version id

🟥 Should not be needed. The DefaultAccessEgress is changed, but I do not think it is serialized.

@t2gran t2gran requested a review from a team as a code owner February 11, 2025 23:38
@t2gran t2gran added this to the 2.7 (next release) milestone Feb 11, 2025
@t2gran t2gran added the Entur Test This is currently being tested at Entur label Feb 11, 2025
@codecov
Copy link

codecov bot commented Feb 11, 2025

Codecov Report

Attention: Patch coverage is 92.85714% with 3 lines in your changes missing coverage. Please review.

Project coverage is 70.45%. Comparing base (e26cbb5) to head (87c47d9).
Report is 215 commits behind head on dev-2.x.

Files with missing lines Patch % Lines
...aptor/api/model/AbstractAccessEgressDecorator.java 66.66% 1 Missing and 1 partial ⚠️
...ipplanner/raptor/api/model/RaptorAccessEgress.java 0.00% 1 Missing ⚠️
Additional details and impacted files
@@              Coverage Diff              @@
##             dev-2.x    #6455      +/-   ##
=============================================
+ Coverage      70.31%   70.45%   +0.13%     
- Complexity     18158    18202      +44     
=============================================
  Files           2058     2061       +3     
  Lines          76942    76934       -8     
  Branches        7773     7765       -8     
=============================================
+ Hits           54101    54202     +101     
+ Misses         20086    19961     -125     
- Partials        2755     2771      +16     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

…ssEgress.

The code did not work because the access/egress is can be wrapped inside Raptor.
@t2gran t2gran force-pushed the fix_npe_in_via_search branch from b866b5e to 1386fc3 Compare February 12, 2025 08:49
…orAccessEgress.java

Co-authored-by: Leonard Ehrenfried <[email protected]>
@vpaturet vpaturet changed the title Fix ClassCastExcaption in Itinerary mapper Fix ClassCastException in Itinerary mapper Feb 14, 2025
Copy link
Contributor

@vpaturet vpaturet left a comment

Choose a reason for hiding this comment

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

Just a minor comment.

@t2gran t2gran merged commit 792c98f into opentripplanner:dev-2.x Feb 20, 2025
6 checks passed
@t2gran t2gran deleted the fix_npe_in_via_search branch February 20, 2025 14:21
t2gran pushed a commit that referenced this pull request Feb 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Entur Test This is currently being tested at Entur

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants