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 Nullable Reference Types on OpenQA.Selenium.Internal #14840

Merged
merged 1 commit into from
Dec 1, 2024

Conversation

RenderMichael
Copy link
Contributor

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

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 across multiple files in the OpenQA.Selenium.Internal namespace.
  • Updated method signatures and variable declarations to accommodate nullable types.
  • Refactored properties and methods for improved code clarity and safety.

Changes walkthrough 📝

Relevant files
Enhancement
ICapabilities.cs
Enable nullable reference types and update method signature

dotnet/src/webdriver/ICapabilities.cs

  • Enabled nullable reference types.
  • Updated GetCapability method to return nullable object.
  • +3/-1     
    AndroidOptions.cs
    Enable nullable reference types and refactor properties   

    dotnet/src/webdriver/Internal/AndroidOptions.cs

  • Enabled nullable reference types.
  • Updated properties to use nullable types.
  • Refactored constructor to use auto-properties.
  • +7/-19   
    FileUtilities.cs
    Enable nullable reference types and update variable declarations

    dotnet/src/webdriver/Internal/FileUtilities.cs

  • Enabled nullable reference types.
  • Updated variable declarations to use nullable types.
  • +7/-5     
    IFindsElement.cs
    Enable nullable reference types                                                   

    dotnet/src/webdriver/Internal/IFindsElement.cs

    • Enabled nullable reference types.
    +2/-0     
    IHasCapabilitiesDictionary.cs
    Enable nullable reference types                                                   

    dotnet/src/webdriver/Internal/IHasCapabilitiesDictionary.cs

    • Enabled nullable reference types.
    +2/-0     
    ResourceUtilities.cs
    Enable nullable reference types and refactor methods         

    dotnet/src/webdriver/Internal/ResourceUtilities.cs

  • Enabled nullable reference types.
  • Refactored PlatformFamily property to use expression-bodied member.
  • Simplified GetPlatformString method.
  • +13/-20 
    ResponseValueJsonConverter.cs
    Enable nullable reference types and update method signatures

    dotnet/src/webdriver/Internal/ResponseValueJsonConverter.cs

  • Enabled nullable reference types.
  • Updated method signatures to return nullable objects.
  • +8/-6     
    ReturnedCapabilities.cs
    Enable nullable reference types and refactor class             

    dotnet/src/webdriver/Internal/ReturnedCapabilities.cs

  • Enabled nullable reference types.
  • Updated constructor and methods to handle nullable types.
  • Refactored properties to use expression-bodied members.
  • +17/-28 

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

    Copy link
    Contributor

    qodo-merge-pro bot commented Dec 1, 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

    Possible Bug
    The GetResourceStream method returns an uninitialized resourceStream variable if neither the file exists nor the embedded resource is found. This could lead to a NullReferenceException.

    Code Smell
    The indexer property throws ArgumentException when key not found instead of using TryGetValue pattern, which is inconsistent with other methods in the class that handle missing keys more gracefully.

    Copy link
    Contributor

    qodo-merge-pro bot commented Dec 1, 2024

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Score
    Possible issue
    Initialize local variables with default values to prevent potential unassigned variable usage

    Initialize copyComplete with a default value of false to ensure it has a value in
    all code paths.

    dotnet/src/webdriver/Internal/FileUtilities.cs [45-46]

    -bool copyComplete;
    +bool copyComplete = false;
     DirectoryInfo sourceDirectoryInfo = new DirectoryInfo(sourceDirectory);
    • Apply this suggestion
    Suggestion importance[1-10]: 8

    Why: The suggestion addresses a potential bug where the local variable 'copyComplete' might be used before being assigned a value, which could lead to compilation errors or undefined behavior. Initializing it with a default value is a good practice.

    8

    💡 Need additional feedback ? start a PR chat

    @nvborisenko
    Copy link
    Member

    Thanks @RenderMichael for contribution!

    @nvborisenko nvborisenko merged commit 51e7267 into SeleniumHQ:trunk Dec 1, 2024
    10 checks passed
    sandeepsuryaprasad pushed a commit to sandeepsuryaprasad/selenium that referenced this pull request Dec 2, 2024
    @RenderMichael RenderMichael deleted the internal branch December 9, 2024 15:14
    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