Skip to content

Add check for null value of serviceCodesRunning in TripPatternForDateMapper - #5239

Merged
leonardehrenfried merged 5 commits into
opentripplanner:dev-2.xfrom
R-OV-NL:fix/nullpointer-for-invalid-serviceOnDate
Jul 20, 2023
Merged

leonardehrenfried merged 5 commits into
opentripplanner:dev-2.xfrom
R-OV-NL:fix/nullpointer-for-invalid-serviceOnDate

Conversation

@Arilith

@Arilith Arilith commented Jul 14, 2023 •

Copy link
Copy Markdown
Contributor

Summary

Fixes an issue where an NullPointer could be thrown while mapping trip patterns for invalid dates.
This is fixed by checking if the serviceCodesRunning set is not null before trying to check if it includes the current trips' service code.

Issue

Closes #5238

Unit tests

New unit tests were added for the TripPatternForDateMapper.
Manual verification was done with the given files in #5238 and debugging in IntelliJ, to see if the issue has been solved.

Documentation

Comments were added where needed.

@Arilith
Arilith requested a review from a team as a code owner July 14, 2023 11:12
@codecov

codecov Bot commented Jul 14, 2023 •

Copy link
Copy Markdown

Codecov Report

Patch coverage: 100.00% and project coverage change: +0.01 🎉

Comparison is base (b7dd2a1) 65.70% compared to head (402152b) 65.71%.

Additional details and impacted files
@@              Coverage Diff              @@
##             dev-2.x    #5239      +/-   ##
=============================================
+ Coverage      65.70%   65.71%   +0.01%     
- Complexity     14725    14732       +7     
=============================================
  Files           1770     1770              
  Lines          68556    68583      +27     
  Branches        7288     7284       -4     
=============================================
+ Hits           45044    45071      +27     
- Misses         21016    21022       +6     
+ Partials        2496     2490       -6     
Impacted Files Coverage Δ
...pter/transit/mappers/TripPatternForDateMapper.java 84.37% <100.00%> (+2.23%) ⬆️

... and 9 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@Arilith Arilith changed the title Added check for null value of serviceCodesRunning in TripPatternForDateMapper.java Add check for null value of serviceCodesRunning in TripPatternForDateMapper.java Jul 14, 2023

// ServiceCodesRunning is potentially null if the date is not present in the original GTFS.
// At that point we can simply return null, as there are no trips running on that date.
if (serviceCodesRunning == null) {

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.

This looks ok, but can you please add a test for this code?

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.

If you're not sure how to do it, get in touch and I can help.

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.

I've added a test for my new addition, and also for the whole class as a whole, as it wasn't tested at all before.

…added tests for this class in TripPatternForDateMapperTest.java.
@leonardehrenfried leonardehrenfried added the !Bug Apply to issues describing a bug and PRs witch fixes it. label Jul 17, 2023
@leonardehrenfried

Copy link
Copy Markdown
Member

The test looks good but we want to move away from complex test setups that "build the world". I've taken the liberty to simplify yours: leonardehrenfried@5bcd5cd

If you're ok with this, can you pull it into your branch?

@leonardehrenfried leonardehrenfried changed the title Add check for null value of serviceCodesRunning in TripPatternForDateMapper.java Add check for null value of serviceCodesRunning in TripPatternForDateMapper Jul 17, 2023
@t2gran t2gran added this to the 2.4 (next release) milestone Jul 18, 2023
@leonardehrenfried

Copy link
Copy Markdown
Member

Since we just spoke, here is a reminder to pull my code into your branch.

…lid-serviceOnDate

Simplify test test setup
@leonardehrenfried
leonardehrenfried merged commit 9a6d12f into opentripplanner:dev-2.x Jul 20, 2023
t2gran pushed a commit that referenced this pull request Jul 20, 2023
@Arilith
Arilith deleted the fix/nullpointer-for-invalid-serviceOnDate branch June 11, 2025 13:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

!Bug Apply to issues describing a bug and PRs witch fixes it.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NullPointerException in the TripPatternForDateMapper while writing GTFS-RT data to graph

4 participants