[Nullable] Enable project nullability on Akka.Cluster.Metrics#8067
Open
MattKotsenas wants to merge 10 commits intoakkadotnet:devfrom
Open
[Nullable] Enable project nullability on Akka.Cluster.Metrics#8067MattKotsenas wants to merge 10 commits intoakkadotnet:devfrom
MattKotsenas wants to merge 10 commits intoakkadotnet:devfrom
Conversation
Add #nullable enable to DateTimeExtensions, IMetricsCollector, and AnyNumber. These are leaf types with no nullable reference concerns - purely value types and a simple interface. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…trics Add #nullable enable to EWMA, ClusterMetricMessages, MetricsGossip, and ClusterMetricsMessageSerializer. Use null-forgiving operator on Deserialize-as-IMetricsSelector casts that are trusted to succeed per existing comments and serialization contracts. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add #nullable enable to ClusterMetricsSettings, ClusterMetricsEvents, and StandardMetrics. All reference type properties are initialized in constructors with no nullable concerns. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add #nullable enable to DefaultCollector and MetricsCollectorBuilder. Mark processes array as nullable in GetCpuUsages (initialized to null, used in finally block). Use null-forgiving on AssemblyQualifiedName for the concrete DefaultCollector type. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add #nullable enable to MetricSelectors, WeightedRoutees, and ClusterMetricsRouting. Mark optional constructor parameters as nullable (metricsSelector, supervisorStrategy, routerDispatcher, paths). Use null! for surrogate properties populated via deserialization. Mark Resizer override return as nullable. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add #nullable enable to ClusterMetrics, ClusterMetricsCollector, ClusterMetricsSupervisor, and ClusterMetricsStrategy. No nullable concerns - all reference fields are initialized in constructors. This completes nullable annotation coverage for all source files in Akka.Cluster.Metrics. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Now that all source files are annotated, replace per-file #nullable enable directives with a single <Nullable>enable</Nullable> in the csproj. This matches the pattern used by TestKit.Xunit and TestKit.Xunit2. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Surrogate DTOs are populated via object initializers in ToSurrogate, but their public properties should honestly reflect that they have no constructor - marking them nullable is accurate since a default- constructed surrogate has all nulls. The FromSurrogate methods pass these values to constructors that already accept nullable parameters, so no behavioral change. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Approve public API surface changes from nullable annotations: constructor parameters marked nullable, surrogate properties marked nullable, Resizer override return marked nullable, EWMA.Equals parameter marked nullable. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes
Enable nullable project-wide for Akka.Cluster.Metrics. This is annotation-only - no behavioral changes, no new null guards. Two files (Metric.cs, NodeMetrics.cs) already had per-file
#nullable enable; those directives are removed since the project-level setting now covers them.Nullable annotation decisions
Marked nullable (these can genuinely be null):
AdaptiveLoadBalancingRoutingLogic(metricsSelector?)MixMetricsSelector.Instancevia??AdaptiveLoadBalancingPool(metricsSelector?, supervisorStrategy?, routerDispatcher?)??-coalesced to defaults in constructor body or base callAdaptiveLoadBalancingGroup(metricsSelector?, paths?, routerDispatcher?)Groupbase constructor already handles null paths viapaths?.ToArray() ?? Array.Empty<string>()ResizeroverrideProcess[]? processesinGetCpuUsagesEWMA.Equals(EWMA?)/Equals(object?)IEquatable<T>andobject.Equalsoverride signaturesMetricsSelector,SupervisorStrategy,RouterDispatcher,Paths)?is honest.FromSurrogatepasses them to constructors that already accept nullable params, so no behavioral change.Null-forgiving
!(trusted to be non-null by contract):typeof(DefaultCollector).AssemblyQualifiedName!AssemblyQualifiedNameis never null for loaded typesDeserialize(...) as IMetricsSelector)!(3 sites in serializer)ToBinaryonly serializesIMetricsSelectorsubtypes, soFromBinaryis guaranteed to get the right type back. Existing comment says "should be safe because we serialized only the right subtypes." Pre-existingascasts; we added!to satisfy nullable analysis without changing the cast pattern.Checklist