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] Add nullability annotations to Proxy #14861

Merged
merged 5 commits into from
Dec 6, 2024

Conversation

RenderMichael
Copy link
Contributor

@RenderMichael RenderMichael commented Dec 6, 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

Add nullability annotations to Proxy. Dictionary lookups are significantly improved, with double- or triple-lookups turning into a single one.

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

  • Added nullability annotations to the Proxy class to improve code safety and clarity.
  • Optimized dictionary lookups by replacing multiple lookups with TryGetValue method calls.
  • Enhanced error handling by adding exceptions for null elements in lists.
  • Simplified property getters using expression-bodied members for cleaner code.

Changes walkthrough 📝

Relevant files
Enhancement
Proxy.cs
Add nullability annotations and optimize dictionary lookups

dotnet/src/webdriver/Proxy.cs

  • Enabled nullability annotations for the Proxy class.
  • Improved dictionary lookups by using TryGetValue.
  • Added exception handling for null elements in lists.
  • Simplified property getters using expression-bodied members.
  • +65/-101

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

    Copy link
    Contributor

    qodo-merge-pro bot commented Dec 6, 2024

    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 Reference
    The TryGetValue pattern used throughout the constructor could still lead to null reference issues if ToString() is called on a null object value. Additional null checks may be needed.

    Exception Handling
    The new ArgumentException for null elements in noProxy list could cause runtime failures for existing code that previously handled nulls silently. Consider logging warnings instead.

    Copy link
    Contributor

    qodo-merge-pro bot commented Dec 6, 2024

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Score
    Possible issue
    Use pattern matching with Array type instead of direct casting to handle different array types safely

    The addressesAsArray array is cast directly to object?[] which could fail at runtime
    if the array is of a different type. Use pattern matching with is to safely handle
    different array types.

    dotnet/src/webdriver/Proxy.cs [138-144]

    -else if (noProxy is object?[]  addressesAsArray)
    +else if (noProxy is Array addressesAsArray) 
     {
    -    foreach (object? address in addressesAsArray)
    +    foreach (var address in addressesAsArray)
         {
             bypassAddresses.Add(address?.ToString() ?? throw new ArgumentException("noProxy list contained null element", nameof(settings)));
         }
     }
    • Apply this suggestion
    Suggestion importance[1-10]: 7

    Why: The suggestion improves type safety by using pattern matching with the more general Array type instead of a specific array type, preventing potential runtime casting exceptions when handling different array types.

    7

    💡 Need additional feedback ? start a PR chat

    @nvborisenko
    Copy link
    Member

    Thx Michael!

    @nvborisenko nvborisenko merged commit be90e2f into SeleniumHQ:trunk Dec 6, 2024
    9 of 10 checks passed
    @RenderMichael RenderMichael deleted the proxy branch December 6, 2024 22:03
    sandeepsuryaprasad pushed a commit to sandeepsuryaprasad/selenium that referenced this pull request Dec 7, 2024
    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