Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[dotnet] Annotate nullability on command repository #14888

Open
wants to merge 3 commits into
base: trunk
Choose a base branch
from

Conversation

RenderMichael
Copy link
Contributor

@RenderMichael RenderMichael commented Dec 11, 2024

User description

Thanks for contributing to Selenium!
A PR well described will help maintainers to quickly review and merge it

Before submitting your PR, please check our contributing guidelines.
Avoid large PRs, help reviewers by making them as simple and short as possible.

Description

Annotates nullability on the CommandInfoRepository class, as well as its sole implementation

Motivation and Context

Contributes to #14640

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • I have read the contributing document.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

PR Type

enhancement


Description

  • Enabled nullable reference types in the CommandInfoRepository and W3CWireProtocolCommandInfoRepository classes.
  • Annotated methods with nullability information to improve code safety and clarity.
  • Enhanced method documentation to include exceptions and return value details.
  • Refactored dictionary access in GetCommandInfo method to use TryGetValue.
  • Simplified property getters in W3CWireProtocolCommandInfoRepository using expression-bodied members.

Changes walkthrough 📝

Relevant files
Enhancement
CommandInfoRepository.cs
Annotate nullability and improve method documentation       

dotnet/src/webdriver/CommandInfoRepository.cs

  • Enabled nullable reference types.
  • Added nullability annotations to methods.
  • Improved exception documentation for methods.
  • Refactored method to use TryGetValue for dictionary access.
  • +15/-7   
    W3CWireProtocolCommandInfoRepository.cs
    Enable nullability and simplify property getters                 

    dotnet/src/webdriver/Remote/W3CWireProtocolCommandInfoRepository.cs

  • Enabled nullable reference types.
  • Simplified property getters using expression-bodied members.
  • +4/-8     

    💡 PR-Agent usage: Comment /help "your question" on any pull request to receive relevant information

    Copy link
    Contributor

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Null Check
    The IsCommandNameDefined method should validate that commandName is not null before accessing the dictionary, since it has a documented ArgumentNullException

    Possible Bug
    The FindCommandName method compares CommandInfo objects using == operator which may not work as expected for reference equality. Consider implementing proper equality comparison

    Copy link
    Contributor

    qodo-merge-pro bot commented Dec 11, 2024

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Score
    Possible issue
    Add parameter validation to prevent null reference exceptions

    Add null check for commandInfo parameter in FindCommandName method to avoid
    potential NullReferenceException when comparing values.

    dotnet/src/webdriver/CommandInfoRepository.cs [72-76]

     public string? FindCommandName(CommandInfo commandInfo)
     {
    +    if (commandInfo == null)
    +        throw new ArgumentNullException(nameof(commandInfo));
    +        
         foreach (KeyValuePair<string, CommandInfo> pair in this.commandDictionary)
         {
             if (pair.Value == commandInfo)
    • Apply this suggestion
    Suggestion importance[1-10]: 8

    Why: The suggestion addresses a critical null reference safety issue by adding parameter validation, which is especially important given the PR's focus on enabling nullable reference types and improving exception handling.

    8
    Add consistent null parameter validation across public methods

    Add null check for commandName parameter in GetCommandInfo method to maintain
    consistency with other methods that throw ArgumentNullException for null command
    names.

    dotnet/src/webdriver/CommandInfoRepository.cs [90-95]

     public T? GetCommandInfo<T>(string commandName) where T : CommandInfo
     {
    +    if (commandName == null)
    +        throw new ArgumentNullException(nameof(commandName));
    +        
         if (this.commandDictionary.TryGetValue(commandName, out CommandInfo? info))
         {
             return info as T;
         }
    • Apply this suggestion
    Suggestion importance[1-10]: 8

    Why: The suggestion maintains consistency with other methods in the codebase that throw ArgumentNullException for null parameters, aligning with the PR's goal of improving null safety and exception documentation.

    8

    💡 Need additional feedback ? start a PR chat

    @RenderMichael
    Copy link
    Contributor Author

    Format issues seems to be coming from rust/src/lock.rs, and test failure is in //java/test/org/openqa/selenium:ClickTest-firefox-beta. I think this PR has no issues.

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

    Successfully merging this pull request may close these issues.

    2 participants