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 Log protocol #15239

Merged
merged 1 commit into from
Feb 6, 2025

Conversation

RenderMichael
Copy link
Contributor

@RenderMichael RenderMichael commented Feb 5, 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 Log protocol

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 multiple Log protocol classes.

  • Added nullability annotations to event handlers and parameters.

  • Introduced ArgumentNullException for constructor parameter validation.

  • Improved code clarity and safety across Log protocol implementations.


Changes walkthrough 📝

Relevant files
Enhancement
Log.cs
Enable nullable reference types in `Log` base class           

dotnet/src/webdriver/DevTools/Log.cs

  • Enabled nullable reference types.
  • Annotated EntryAdded event with nullable type.
  • +3/-1     
    V130Log.cs
    Add nullability and validation in `V130Log`                           

    dotnet/src/webdriver/DevTools/v130/V130Log.cs

  • Enabled nullable reference types.
  • Added ArgumentNullException for constructor parameter validation.
  • Updated event handler to accept nullable sender.
  • Simplified event propagation logic.
  • +9/-5     
    V131Log.cs
    Add nullability and validation in `V131Log`                           

    dotnet/src/webdriver/DevTools/v131/V131Log.cs

  • Enabled nullable reference types.
  • Added ArgumentNullException for constructor parameter validation.
  • Updated event handler to accept nullable sender.
  • Simplified event propagation logic.
  • +9/-5     
    V132Log.cs
    Add nullability and validation in `V132Log`                           

    dotnet/src/webdriver/DevTools/v132/V132Log.cs

  • Enabled nullable reference types.
  • Added ArgumentNullException for constructor parameter validation.
  • Updated event handler to accept nullable sender.
  • Simplified event propagation logic.
  • +8/-4     
    V85Log.cs
    Add nullability and validation in `V85Log`                             

    dotnet/src/webdriver/DevTools/v85/V85Log.cs

  • Enabled nullable reference types.
  • Added ArgumentNullException for constructor parameter validation.
  • Updated event handler to accept nullable sender.
  • Simplified event propagation logic.
  • +8/-4     

    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 5, 2025

    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

    Missing Null Check

    The constructor does not validate the adapter parameter for null, unlike the other version classes that throw ArgumentNullException

    this.adapter = adapter;
    this.adapter.EntryAdded += OnAdapterEntryAdded;

    Copy link
    Contributor

    qodo-merge-pro bot commented Feb 5, 2025

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    Possible issue
    Add missing null check

    Add null check for adapter parameter in constructor using throw pattern to match
    other version implementations

    dotnet/src/webdriver/DevTools/v85/V85Log.cs [40-43]

     public V85Log(LogAdapter adapter)
     {
    -    this.adapter = adapter;
    +    this.adapter = adapter ?? throw new ArgumentNullException(nameof(adapter));
         this.adapter.EntryAdded += OnAdapterEntryAdded;
    • Apply this suggestion
    Suggestion importance[1-10]: 8

    __

    Why: Adding null check for constructor parameter is crucial for preventing NullReferenceException and maintaining consistency with other version implementations. This is a significant defensive programming practice.

    Medium
    General
    Make field immutable

    Mark the adapter field as readonly since it's only set in the constructor and
    never modified

    dotnet/src/webdriver/DevTools/v132/V132Log.cs [33]

    -private LogAdapter adapter;
    +private readonly LogAdapter adapter;
    • Apply this suggestion
    Suggestion importance[1-10]: 5

    __

    Why: Making the field readonly improves code safety by preventing accidental modifications after initialization, though the impact is moderate since the field is already private and only set in constructor.

    Low

    @RenderMichael
    Copy link
    Contributor Author

    Failures are unrelated to this PR

    //java/test/org/openqa/selenium/mobile:NetworkConnectionTest
    //java/test/org/openqa/selenium/remote:RemoteWebDriverScreenshotTest
    //java/test/org/openqa/selenium/remote:RemoteWebDriverScreenshotTest-firefox-beta
    //rb/spec/integration/selenium/webdriver:network-firefox-beta-bidi
    //rb/spec/integration/selenium/webdriver:network-firefox-bidi

    @RenderMichael RenderMichael merged commit 445ba70 into SeleniumHQ:trunk Feb 6, 2025
    9 of 10 checks passed
    @RenderMichael RenderMichael deleted the nullable-log branch February 6, 2025 05:29
    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