Fix: add null checks for DOM elements in GetHoldingInformation#29
Open
HashidaTKS wants to merge 1 commit into
Open
Fix: add null checks for DOM elements in GetHoldingInformation#29HashidaTKS wants to merge 1 commit into
HashidaTKS wants to merge 1 commit into
Conversation
Three FirstOrDefault() calls were not null-checked before being dereferenced:
- GetElementsByClassName("RaceList_Box").FirstOrDefault() — the top-level container
- GetElementsByClassName("RaceList_DataTitle").FirstOrDefault() — the title element per item
- GetElementsByClassName("RaceData").FirstOrDefault() — the data element per race item
If the page is empty or the structure changes, these return null and cause
NullReferenceException. Add explicit null guards and skip or return early
with an empty HoldingInformation when the container is absent.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
問題点
Scraper.GetHoldingInformation()で以下の3箇所においてFirstOrDefault()の結果を null チェックせずに使用していた。GetElementsByClassName("RaceList_Box").FirstOrDefault()(line 346)GetElementsByClassName("RaceList_DataTitle").FirstOrDefault()(line 354)GetElementsByClassName("RaceData").FirstOrDefault()(line 374)開催情報がない日付や、ページ構造の変化により各要素が取得できなかった場合に
NullReferenceExceptionが発生する。改善内容
RaceList_Boxが見つからない場合は警告ログを出力して空のHoldingInformationを返すRaceList_DataTitle/RaceDataが null の場合はその行をスキップ(continue)Test plan
🤖 Generated with Claude Code