-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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] Add nullability to CookieJar
#14874
Conversation
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @RenderMichael !
Let's postpone nullability for cookies, we should understand why https://www.w3.org/TR/webdriver2/#get-named-cookie is not used. According specification, seems cookie name cannot be null. But the current implementation allows it to be null. |
The nullability annotations in this PR are in line with what the code actually does. The cookie getter is more like a Maybe we should introduce a new method which throws when the cookie is not found? I can add that in another PR. |
I actually use these methods in my test assertions, with methods like “assert cookie with name x does not exist”. The null check makes this easy. That’s my guess about why this was implemented this way. Because “missing cookie” is a valid scenario and it’s easier to check for null instead of catching an exception. |
It was implemented 12 years ago, and in my opinion it is wrong! |
That’s completely fair. One solution is to obsolete the current method, and make two new methods: This current PR just annotates the existing |
From one point of view it is better to not touch the current implementation, nullability here just reflects the current situation. From other hand the following is definitely bad: public void DeleteCookieNamed(string name)
{
Dictionary<string, object> parameters = new Dictionary<string, object>();
parameters.Add("name", name);
this.driver.InternalExecute(DriverCommand.DeleteCookie, parameters);
}
public void DeleteCookie(Cookie cookie)
{
if (cookie != null)
{
this.DeleteCookieNamed(cookie.Name);
}
} Most interesting is that Give me time to think. I want to go further. I am OK with the changes in this PR. |
Yes, it is, in Firefox. So, we should fix it before introducing nullability. |
OK, I removed nullability from the offending method |
Don't spend your time on this area, on hold. |
Well you found a bug related to nullness, so that’s something :) Yes my initial plan was just to quickly sweep through this section and reinforce whatever the code already does (in this case, accepting null and doing no-op). |
Nullability is not only about runtime, it overlaps declaration. I already said: it will be challenging as for you as for us. |
Blocked by #14883 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will be long story, let's proceed with current state. Thank you @RenderMichael !
Current state is:
|
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
Adds nullable reference types to
CookieJar
andICookieJar
Broken off from #14669
Motivation and Context
Contributes to #14640
Types of changes
Checklist
PR Type
enhancement
Description
CookieJar
andICookieJar
to improve null safety.ArgumentNullException
for constructor and method parameters inCookieJar
.GetAllCookies
method into a property inCookieJar
for better encapsulation.ICookieJar
to accept nullable parameters, enhancing flexibility.Changes walkthrough 📝
CookieJar.cs
Add nullability and refactor `CookieJar` class
dotnet/src/webdriver/CookieJar.cs
GetAllCookies
method into a property.ICookieJar.cs
Update `ICookieJar` interface for nullability
dotnet/src/webdriver/ICookieJar.cs