Guard null-reference on methods[0].method in FindBestMethodImpl#27623
Open
euxaristia wants to merge 1 commit into
Open
Guard null-reference on methods[0].method in FindBestMethodImpl#27623euxaristia wants to merge 1 commit into
methods[0].method in FindBestMethodImpl#27623euxaristia wants to merge 1 commit into
Conversation
The error path in `FindBestMethodImpl` could dereference a null `methods[0].method` when the `methods` array is empty or contains entries with a null `method` field. Guard both conditions before accessing `.Name`.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds a defensive guard in FindBestMethodImpl to prevent a null-reference when forming the generic-method-argument-count error message, falling back to "<unknown>" when the method name cannot be obtained.
Changes:
- Introduce a safe
methodNamelocal computed frommethods[0].method?.Name(with additional array-length guard). - Use the guarded
methodNamewhen formattingExtendedTypeSystem.MethodGenericArgumentCountException.
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.
PR Summary
Guard against null-reference when accessing
methods[0].method.Namein the error path ofFindBestMethodImpl.PR Context
When
candidates.Count == 0and the first condition (all methods are static generic type definitions) is false, the else-if branch on line 1639 accessesmethods[0].method.Name. This can throw aNullReferenceExceptionifmethods[0].methodis null or ifmethods.Lengthis 0. Add a null check and fall back to"<unknown>".PR Checklist