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 network interactions #15209

Merged
merged 2 commits into from
Feb 3, 2025

Conversation

RenderMichael
Copy link
Contributor

@RenderMichael RenderMichael commented Feb 1, 2025

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.

Annotate nullability on network interactions

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, Bug fix


Description

  • Annotated nullability across network-related classes and methods.

  • Added null-checks and exception handling for method parameters.

  • Introduced nullable reference types in multiple files.

  • Improved code clarity and fixed typos in comments.


Changes walkthrough 📝

Relevant files
Enhancement
8 files
Network.cs
Enable nullable reference types and add null-checks.         
+18/-9   
V130Network.cs
Add null-checks and enable nullable reference types.         
+50/-7   
V131Network.cs
Add null-checks and enable nullable reference types.         
+50/-7   
V132Network.cs
Add null-checks and enable nullable reference types.         
+50/-7   
V85Network.cs
Add null-checks and enable nullable reference types.         
+51/-8   
ICredentials.cs
Enable nullable reference types for credentials interface.
+2/-0     
PasswordCredentials.cs
Enable nullable reference types for password credentials.
+5/-3     
UserAgent.cs
Add constructors and nullable reference types for user agent.
+24/-2   
Bug fix
1 files
NetworkManager.cs
Refactor type casting and improve null safety.                     
+1/-1     

Need help?
  • Type /help how to ... in the comments thread for any questions about Qodo Merge usage.
  • Check out the documentation for more information.
  • Copy link
    Contributor

    qodo-merge-pro bot commented Feb 1, 2025

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

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

    Type Cast

    Direct cast from ICredentials to PasswordCredentials could throw InvalidCastException if credentials are of a different type. Should use 'as' operator or pattern matching with null check.

    PasswordCredentials credentials = (PasswordCredentials)authenticationHandler.Credentials;
    Null Assignment

    Constructor assigns null! to UserAgentString but property is not nullable. This could lead to NullReferenceException at runtime.

    UserAgentString = null!;

    Copy link
    Contributor

    qodo-merge-pro bot commented Feb 1, 2025

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Score
    Possible issue
    Add null and type validation

    Add null check and type validation for authenticationHandler.Credentials before
    casting to PasswordCredentials to prevent potential runtime exceptions.

    dotnet/src/webdriver/NetworkManager.cs [203]

    -PasswordCredentials credentials = (PasswordCredentials)authenticationHandler.Credentials;
    +if (authenticationHandler.Credentials is not PasswordCredentials credentials)
    +{
    +    throw new InvalidOperationException("Authentication handler credentials must be of type PasswordCredentials");
    +}
    • Apply this suggestion
    Suggestion importance[1-10]: 8

    Why: The suggestion addresses a potential runtime error by adding proper type validation and null checking before casting credentials, which could prevent crashes and improve error handling.

    8

    @RenderMichael RenderMichael merged commit 9a3390d into SeleniumHQ:trunk Feb 3, 2025
    10 checks passed
    @RenderMichael RenderMichael deleted the nullable-network branch February 3, 2025 05:32
    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.

    1 participant