-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Nullable annotations for X11 #17814
base: master
Are you sure you want to change the base?
Nullable annotations for X11 #17814
Conversation
You can test this PR using the following package version. |
} | ||
} | ||
|
||
return null; | ||
return new FallBackScreen(default, _x11); |
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.
I think that's not a valid behavior to return a fake screen for invalid parameter here. It's a problem of the calling code to handle a missing screen properly.
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.
Out of 10 Screen
implementations, this one was the only one returning null - it's fairly recent, and should have respected the non-null contract. I guess it was missed due to the nullability mismatch here.
I've changed it to throw instead. We should never get here anyway: the key comes from the ScreenKeys
property, and should always be found in the for
loop above.
src/Avalonia.X11/X11Platform.cs
Outdated
new X11PlatformOptions())); | ||
{ | ||
var options = AvaloniaLocator.Current.GetService<X11PlatformOptions>() ?? new X11PlatformOptions(); | ||
_ = new AvaloniaX11Platform(options); |
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.
Maybe add a static Initialize method? Relying on ctor side effects outside of the class itself seems a bit out of place
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.
I've reverted to the old implementation and added null!
initializers instead for now. We completely control the caller so it's fine.
The AvaloniaX11Platform
instance registers itself inside the AvaloniaLocator
currently, so replacing that with a static initialization method doesn't really help. Ideally we should refactor that code to completely decouple initialization and registration, but that's out of scope of this PR.
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.
LGTM in general
f3a587f
to
51efc8f
Compare
You can test this PR using the following package version. |
What does the pull request do?
This PR enables and fixes nullable annotations for the Avalonia.X11 project.
Remarks
While most of the changes are straightforward,
X11Screens.Randr15ScreensImpl.CreateScreenFromKey()
has been changed to return an emptyFallBackScreen
instead ofnull
in case of failure. This code path is called fromScreensBase<TKey,TScreen>.EnsureScreens()
, where null is definitely not expected, as that would insert a null screen intoAllScreens
, causing NREs:Avalonia/src/Avalonia.Controls/Platform/IScreenImpl.cs
Line 164 in 33bd02c