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 WebDriver.SessionId #15350

Merged
merged 1 commit into from
Feb 28, 2025

Conversation

RenderMichael
Copy link
Contributor

@RenderMichael RenderMichael commented Feb 28, 2025

User description

Description

Annotate nullability on WebDriver.SessionId and the related interface IHasSessionId.

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 WebDriver and IHasSessionId.

  • Annotated SessionId property with nullability support.

  • Improved code clarity and null safety in WebDriver.

  • Added #nullable enable directives to relevant files.


Changes walkthrough 📝

Relevant files
Enhancement
IHasSessionId.cs
Enable nullable reference types in `IHasSessionId`             

dotnet/src/webdriver/IHasSessionId.cs

  • Enabled nullable reference types in the file.
  • Added #nullable enable directive at the namespace level.
  • +2/-0     
    WebDriver.cs
    Enable nullable reference types in `WebDriver`                     

    dotnet/src/webdriver/WebDriver.cs

  • Enabled nullable reference types in the file.
  • Annotated SessionId property for nullability.
  • Removed redundant #nullable restore directive.
  • Improved null safety in Dispose method.
  • +3/-7     

    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:

    🎫 Ticket compliance analysis 🔶

    14640 - Partially compliant

    Compliant requirements:

    • Added nullability annotations to WebDriver.SessionId and IHasSessionId
    • Enabled nullable reference types in the modified files

    Non-compliant requirements:

    • Enable Nullable Reference Types in .csproj and bazel files

    Requires further human verification:

    • Verify that the nullability annotations are correct and prevent null reference exceptions in practice
    ⏱️ Estimated effort to review: 1 🔵⚪⚪⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Null Assignment

    The SessionId property is set to null! in Dispose method which could potentially cause issues if the property is accessed after disposal. Consider making the property nullable instead.

    this.SessionId = null!;

    Copy link
    Contributor

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    Possible issue
    Add nullable annotation to property

    Initialize SessionId property with a nullable annotation since it can be null.
    Change the property type to SessionId? to properly reflect nullability.

    dotnet/src/webdriver/WebDriver.cs [192]

    -public SessionId SessionId { get; private set; }
    +public SessionId? SessionId { get; private set; }
    • Apply this suggestion
    Suggestion importance[1-10]: 8

    __

    Why: The suggestion correctly identifies that SessionId should be marked as nullable since it can be set to null (as seen in line 742). This improves type safety and makes the nullability explicit in the API.

    Medium
    • More

    @RenderMichael RenderMichael merged commit 8d25bef into SeleniumHQ:trunk Feb 28, 2025
    10 checks passed
    @RenderMichael RenderMichael deleted the nullable-session branch February 28, 2025 22: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.

    1 participant