Fix: add null checks for Payout_Detail_Table elements in GetRaceResult#28
Open
HashidaTKS wants to merge 1 commit into
Open
Fix: add null checks for Payout_Detail_Table elements in GetRaceResult#28HashidaTKS wants to merge 1 commit into
HashidaTKS wants to merge 1 commit into
Conversation
GetRaceResult accessed firstPayoutTable and secondPayoutTable without null checks. If the page structure changes or the race result is unavailable, GetElementsByClassName returns an empty collection and FirstOrDefault() returns null, causing NullReferenceException on the next method call. Add explicit null guards for the two table roots and use null-conditional operators (?.) throughout the payout extraction chain. Return null early with a log message when the page structure is unexpected. 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.GetRaceResult()でGetElementsByClassName("Payout_Detail_Table").FirstOrDefault()の結果を null チェックせずに直接メソッドチェーンしていた。ページ構造が変化した場合や払い戻し情報が存在しないレースの場合、
FirstOrDefault()がnullを返し、直後の.GetElementsByClassName()呼び出しでNullReferenceExceptionが発生する。また、各払い戻し情報(単勝・馬連・馬単など)取得でも同様に null チェックなしのメソッドチェーンが連続していた。
改善内容
firstPayoutTable/secondPayoutTableの null チェックを追加し、null の場合はログを出力してnullを早期リターン?.演算子を使用Test plan
Payout_Detail_Tableが存在しないページでも例外が発生せずnullが返されることを確認🤖 Generated with Claude Code