Skip to content

fix: 셔틀 잔여 시간 정렬 중 null 도착 시각 NPE 방지 - #2410

Open
taejinn wants to merge 1 commit into
developfrom
fix/2409-bus-remain-time-null-sort
Open

fix: 셔틀 잔여 시간 정렬 중 null 도착 시각 NPE 방지#2410
taejinn wants to merge 1 commit into
developfrom
fix/2409-bus-remain-time-null-sort

Conversation

@taejinn

@taejinn taejinn commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

🔍 개요

  • GET /bus에서 정상 도착 시각과 null 시각이 함께 선택되면 셔틀 서비스의 선행 정렬이 BusRemainTime.compareTo():85에서 NPE를 발생시킵니다. 기존 응답 변환의 무효 시간 필터 → 정렬 순서를 사용하여 이번 HTTP 500을 차단합니다.

🚀 주요 변경 내용

  • ShuttleBusService.getShuttleBusRemainTimes().sorted()를 제거합니다. .distinct()는 유지하며, 정렬은 BusService.toResponse()가 남은 시간을 계산할 수 없는 항목을 제외한 뒤 수행합니다.
  • 실제 Route → ShuttleBusService → BusService 경로를 사용하는 회귀 테스트 7개를 추가합니다. 저장소와 외부 서비스 의존성만 mock 처리합니다.
    • 토요일 11:25, 순환 노선의 14:25와 중복 터미널이 있는 주말 하교 노선의 null 시각이 함께 선택되는 조건
    • 셔틀/통학 각각의 정상·null·문자열 시간 혼합, 시간순 정렬, 중복 제거, 운행 종료 항목 제외 및 빈 응답

💬 참고 사항

  • 수정 전 새 테스트 7개 중 3개가 서버와 동일한 NPE 및 BusRemainTime.java:85로 실패했고, 수정 후 전부 통과했습니다.
  • 로컬 검증: ./gradlew test --tests 'in.koreatech.koin.unit.domain.bus.*' bootJar --console=plain 성공. 버스 테스트 25개, 실패/오류/건너뜀 0개이며 애플리케이션 JAR 생성도 성공했습니다. git diff --check도 통과했습니다. 로컬 JDK는 20.0.2이며 GitHub CI는 저장소 설정대로 JDK 17에서 전체 build를 실행합니다.
  • 공개 시간표를 기반으로 토요일 운행 fixture를 구성한 서비스 단위 재현입니다. 원 요청의 파라미터와 당시 DB 스냅샷을 특정하거나 운영 HTTP E2E를 수행한 것은 아닙니다.
  • 이번 변경은 NPE 차단 핫픽스입니다. Route의 방향/운행 구간 판정 및 중복 정류장 선택 불일치는 남습니다. 계산할 수 없는 항목을 제외하는 기존 동작을 유지하며, 누락될 수 있는 버스의 정확한 경로와 출발 시각까지 교정하지는 않습니다. 실제 하교 시간표의 방향 반전으로 시간 순서가 거꾸로인 경로가 통과하는 문제도 #2409에 후속 과제로 기록했습니다.
  • DB·시간표·응답 스키마 변경은 없습니다. 이 커밋을 revert하면 변경을 되돌릴 수 있습니다.

✅ Checklist (완료 조건)

  • 코드 스타일 가이드 준수
  • 테스트 코드 포함됨
  • Reviewers / Assignees / Labels 지정 완료
  • 보안 및 민감 정보 검증 (API 키, 환경 변수, 개인정보 등)

Summary by CodeRabbit

  • Bug Fixes

    • Improved shuttle bus remaining-time results by filtering invalid or unusable routes and removing duplicate entries.
    • Corrected result ordering so the nearest available buses are displayed consistently.
    • Improved handling for weekend, circular, shuttle, and commuting bus routes.
    • Empty results are now returned when no valid route or usable bus information is available.
  • Tests

    • Added coverage for route filtering, duplicate departures, ordering, and supported bus types.

@taejinn taejinn added the 버그 정상적으로 동작하지 않는 문제상황입니다. label Sep 5, 2026
@taejinn taejinn self-assigned this Sep 5, 2026
@coderabbitai

coderabbitai Bot commented Sep 5, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Team

Run ID: 47e68a00-53b4-4cf9-947a-45243cf3eade

📥 Commits

Reviewing files that changed from the base of the PR and between fda3ad8 and c540a8d.

📒 Files selected for processing (2)
  • src/main/java/in/koreatech/koin/domain/bus/service/shuttle/ShuttleBusService.java
  • src/test/java/in/koreatech/koin/unit/domain/bus/ShuttleBusRemainTimeTest.java

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The change removes premature shuttle arrival-time sorting and adds unit coverage for invalid times, duplicate departures, route variants, ordering, and empty results.

Changes

Shuttle arrival-time handling

Layer / File(s) Summary
Remaining-time pipeline
src/main/java/in/koreatech/koin/domain/bus/service/shuttle/ShuttleBusService.java
The stream no longer sorts BusRemainTime values before BusService excludes entries without calculable arrival times.
Remaining-time regression coverage
src/test/java/in/koreatech/koin/unit/domain/bus/ShuttleBusRemainTimeTest.java
Tests cover weekend and circular routes, invalid and duplicate departures, nearest-bus ordering, supported bus types, ended routes, unusable routes, and missing routes.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to c540a

The shuttle and commuting bus remaining-time response now excludes uncalculable entries before ordering, preventing failures when valid and null arrival times are mixed while preserving valid ordered results.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 13 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed [2409] 선행 정렬을 제거하고 기존 응답 흐름의 필터 후 정렬을 사용합니다. 회귀 테스트는 정상·무효 시간 혼합, 시간순 정렬, 중복 제거, 운행 종료 항목, 빈 응답을 검증합니다.
Out of Scope Changes check ✅ Passed 변경 사항은 NPE 방지 수정과 관련 회귀 테스트로 제한됩니다. DB, 시간표, 응답 스키마 또는 후속 노선 판정 과제의 변경은 포함하지 않습니다.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: preventing an NPE caused by null arrival times during shuttle remaining-time sorting.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/2409-bus-remain-time-null-sort

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@dnjswldnd-3513 dnjswldnd-3513 left a comment

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.

확인했습니다!

@taejinn
taejinn marked this pull request as ready for review September 5, 2026 07:54
@github-actions

github-actions Bot commented Sep 5, 2026

Copy link
Copy Markdown

Unit Test Results

   260 files     260 suites   2m 40s ⏱️
1 147 tests 1 144 ✔️ 3 💤 0
1 151 runs  1 148 ✔️ 3 💤 0

Results for commit c540a8d.

public List<BusRemainTime> getShuttleBusRemainTimes(BusType busType, BusStation depart, BusStation arrival) {
List<Route> routes = getShuttleRoutesByBusType(busType);

// 시간 정렬은 BusService에서 계산할 수 없는 항목을 제외한 뒤 수행한다.

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.

BusService 이외의 서비스로직에서 이 메서드를 사용할 수도 있을것 같은데요
이 주석은 너무 이슈 하나에만 집중된 내용같다는 생각이 드네요. 어떻게생각하시나요?

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.

BusService 외 다른 서비스에서 사용할 수 있다는 것까지는 생각하지 못했습니다.

도착 시간이 null인 항목을 먼저 제외하도록 하여 발견한 문제를 해결하고, 정렬까지 이 메서드에서 하도록 수정하는 방향으로 진행해보겠습니다.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

버그 정상적으로 동작하지 않는 문제상황입니다.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[버그] GET /bus 셔틀 도착 시각 정렬 중 NullPointerException 발생

4 participants