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 chrome-based driver services #15154

Merged
merged 3 commits into from
Jan 31, 2025

Conversation

RenderMichael
Copy link
Contributor

@RenderMichael RenderMichael commented Jan 25, 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.

Description

Annotates nullability on chrome-based driver services

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

  • Annotated nullability for driver service classes in Chrome, Edge, and IE.

  • Enabled nullable reference types in relevant files.

  • Improved property definitions and initialization for Internet Explorer driver service.

  • Updated method parameters and return types for null safety.


Changes walkthrough 📝

Relevant files
Enhancement
ChromeDriverService.cs
Annotate nullability in ChromeDriverService                           

dotnet/src/webdriver/Chrome/ChromeDriverService.cs

  • Enabled nullable reference types.
  • Updated constructor parameters to nullable types.
  • Ensured non-nullable usage with null-forgiving operator.
  • +4/-2     
    ChromiumDriverService.cs
    Annotate nullability in ChromiumDriverService                       

    dotnet/src/webdriver/Chromium/ChromiumDriverService.cs

  • Updated constructor parameters to nullable types.
  • Enhanced null safety in base class initialization.
  • +1/-1     
    EdgeDriverService.cs
    Annotate nullability in EdgeDriverService                               

    dotnet/src/webdriver/Edge/EdgeDriverService.cs

  • Enabled nullable reference types.
  • Updated constructor parameters to nullable types.
  • Refactored property accessors for modern syntax.
  • Ensured non-nullable usage with null-forgiving operator.
  • +6/-4     
    InternetExplorerDriverService.cs
    Annotate nullability in InternetExplorerDriverService       

    dotnet/src/webdriver/IE/InternetExplorerDriverService.cs

  • Enabled nullable reference types.
  • Updated constructor parameters to nullable types.
  • Refactored properties to nullable types with default values.
  • Improved XML documentation for clarity and null safety.
  • Enhanced command-line argument generation with null checks.
  • +36/-61 

    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

    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 Safety

    The null-forgiving operator (!) is used on Path.GetDirectoryName() without validating that the path exists first, which could lead to runtime errors if the path is invalid.

    driverPath = Path.GetDirectoryName(driverPath)!;
    Null Safety

    Similar to Chrome service, the null-forgiving operator is used without proper validation of path existence, which could cause runtime errors.

    driverPath = Path.GetDirectoryName(driverPath)!;

    Copy link
    Contributor

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Score
    Possible issue
    Add null check for directory path

    The null-forgiving operator (!) on Path.GetDirectoryName() assumes the path has a
    directory component. Add a null check to handle cases where the path might be a root
    directory or invalid.

    dotnet/src/webdriver/Chrome/ChromeDriverService.cs [72]

    -driverPath = Path.GetDirectoryName(driverPath)!;
    +var dirPath = Path.GetDirectoryName(driverPath);
    +if (dirPath == null)
    +    throw new ArgumentException("Invalid driver path", nameof(driverPath));
    +driverPath = dirPath;
    • Apply this suggestion
    Suggestion importance[1-10]: 8

    Why: The suggestion addresses a potential runtime error by adding proper null checks for Path.GetDirectoryName(). This is important for robustness as the current code assumes the path will always have a directory component.

    8

    @RenderMichael RenderMichael merged commit 96331c5 into SeleniumHQ:trunk Jan 31, 2025
    10 checks passed
    @RenderMichael RenderMichael deleted the chromium-services branch January 31, 2025 05:34
    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