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

Remove Jetbrains nullability attributes #24418

Merged
merged 2 commits into from
Mar 17, 2021
Merged

Remove Jetbrains nullability attributes #24418

merged 2 commits into from
Mar 17, 2021

Conversation

roji
Copy link
Member

@roji roji commented Mar 16, 2021

The first commit corrects a few discrepancies between Jetbrains and the Roslyn nullability and the Roslyn nullability annotations - this is worth going over. The second is mechanical and removes the Jetbrains stuff.

Just for fun, discrepancies were discovered as follows:

  • Parameters with [CanBeNull] but without question mark: \[CanBeNull\][^?,)]*[,)]
  • Parameters with [NotNull] but with question mark: \[NotNull\][^,)]*\?
  • Properties with [param: CanBeNull] but without question mark: grep -nr '\[param: CanBeNull\]' | grep -v \?.
  • Properties with [param: NotNull] but with question mark:

Fixes #14568

@roji roji force-pushed the RemoveJetbrainsNullability branch from 462958a to a2eb46b Compare March 16, 2021 19:56
Copy link
Member Author

@roji roji left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AndriySvyryd here are some other cases where I wasn't too sure. Do the below need to have [DisallowNull] on them? Or allow setting null?

EFCore.Relational/Metadata/Internal/TableBase.cs:101:        public virtual SortedDictionary<IEntityType, IEnumerable<IForeignKey>>? RowInternalForeignKeys { get; [param: NotNull] set; }
EFCore.Relational/Metadata/Internal/TableBase.cs:121:        public virtual Dictionary<IEntityType, bool>? OptionalEntityTypes { get; [param: NotNull] set; }
EFCore/Metadata/SlimForeignKey.cs:84:        private SlimNavigation? DependentToPrincipal { get; [param: NotNull] set; }
EFCore/Metadata/SlimForeignKey.cs:85:        private SlimNavigation? PrincipalToDependent { get; [param: NotNull] set; }
EFCore/Metadata/SlimSkipNavigation.cs:92:        public virtual SlimSkipNavigation? Inverse { get; [param: NotNull] set; }

src/EFCore.Relational/Metadata/IMutableDbFunction.cs Outdated Show resolved Hide resolved
src/EFCore.Relational/Metadata/Internal/DbFunction.cs Outdated Show resolved Hide resolved
@@ -427,7 +427,7 @@ public virtual EntityFrameworkServicesBuilder TryAdd<TService>([NotNull] Func<IS
/// <typeparam name="TService"> The contract for the service. </typeparam>
/// <param name="implementation"> The implementation of the service. </param>
/// <returns> This builder, such that further calls can be chained. </returns>
public virtual EntityFrameworkServicesBuilder TryAdd<TService>([CanBeNull] TService implementation)
public virtual EntityFrameworkServicesBuilder TryAdd<TService>([NotNull] TService implementation)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

However this would be a breaking change

Copy link
Member

@sharwell sharwell Mar 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit of a weird case. There is only one case where null was allowed:

  1. The service is considered a singleton
  2. An instance of this service type has already been added

For this case, the null instance was simply ignored.

Copy link
Member Author

@roji roji Mar 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

However this would be a breaking change

Technically yes... though it's very hard to see how anyone could have been using the API with null in a productive way - it would only mean that we'd start throwing on the case @sharwell described above (ignore already-added singleton).

Am leaving as-is with the change.

@roji roji requested review from AndriySvyryd and a team March 16, 2021 20:02
@roji roji marked this pull request as ready for review March 16, 2021 20:44
@AndriySvyryd
Copy link
Member

@AndriySvyryd here are some other cases where I wasn't too sure. Do the below need to have [DisallowNull] on them? Or allow setting null?

They need [DisallowNull]

@@ -31,7 +30,7 @@ public class ObservableBackedBindingList<T> : SortableBindingList<T>
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public ObservableBackedBindingList([NotNull] ICollection<T> observableCollection)
public ObservableBackedBindingList(ICollection<T> observableCollection)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❔ Did you also validate that all changes occurred in contexts where nullable reference types is enabled?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what you mean here... Can you provide more detail?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sharwell as this is the only unresolved comment, I'm going to go ahead and merge this PR, as the conflict potential with other work is very high. But I'm happy to fix up in a later PR if we need to.

@roji
Copy link
Member Author

roji commented Mar 17, 2021

Thanks for the review and helpful comments @sharwell!

@roji roji force-pushed the RemoveJetbrainsNullability branch from a2eb46b to 809fe7a Compare March 17, 2021 08:56
@roji roji merged commit 809fe7a into main Mar 17, 2021
@roji roji deleted the RemoveJetbrainsNullability branch March 17, 2021 09:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove all Jetbrains nullability annotations
3 participants