Skip to content

Commit 9849af2

Browse files
[Group 9] Enable nullable annotations for Microsoft.Extensions.Hosting.Systemd (#67513)
Fix #43605 * Annotate * Fix API compat check by removing MemberNotNullWhen attribute. Co-authored-by: Eric Erhardt <eric.erhardt@microsoft.com>
1 parent 8ea879a commit 9849af2

6 files changed

Lines changed: 12 additions & 10 deletions

File tree

src/libraries/Microsoft.Extensions.Hosting.Systemd/ref/Microsoft.Extensions.Hosting.Systemd.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
<PropertyGroup>
44
<TargetFrameworks>$(NetCoreAppCurrent);$(NetCoreAppMinimum);netstandard2.1</TargetFrameworks>
5+
<Nullable>enable</Nullable>
56
<EnableDefaultItems>true</EnableDefaultItems>
67
</PropertyGroup>
78

src/libraries/Microsoft.Extensions.Hosting.Systemd/src/Microsoft.Extensions.Hosting.Systemd.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
<PropertyGroup>
44
<TargetFrameworks>$(NetCoreAppCurrent);$(NetCoreAppMinimum);netstandard2.1</TargetFrameworks>
5+
<Nullable>enable</Nullable>
56
<EnableDefaultItems>true</EnableDefaultItems>
67
<PackageDescription>.NET hosting infrastructure for Systemd Services.</PackageDescription>
78
<!-- Use targeting pack references instead of granular ones in the project file. -->

src/libraries/Microsoft.Extensions.Hosting.Systemd/src/ServiceState.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ public struct ServiceState
2626
/// <summary>
2727
/// Create custom ServiceState.
2828
/// </summary>
29-
public ServiceState(string state)
29+
public ServiceState(string state!!)
3030
{
31-
_data = Encoding.UTF8.GetBytes(state ?? throw new ArgumentNullException(nameof(state)));
31+
_data = Encoding.UTF8.GetBytes(state);
3232
}
3333

3434
/// <summary>

src/libraries/Microsoft.Extensions.Hosting.Systemd/src/SystemdLifetime.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ public Task WaitForStartAsync(CancellationToken cancellationToken)
4141
{
4242
_applicationStartedRegistration = ApplicationLifetime.ApplicationStarted.Register(state =>
4343
{
44-
((SystemdLifetime)state).OnApplicationStarted();
44+
((SystemdLifetime)state!).OnApplicationStarted();
4545
},
4646
this);
4747
_applicationStoppingRegistration = ApplicationLifetime.ApplicationStopping.Register(state =>
4848
{
49-
((SystemdLifetime)state).OnApplicationStopping();
49+
((SystemdLifetime)state!).OnApplicationStopping();
5050
},
5151
this);
5252

src/libraries/Microsoft.Extensions.Hosting.Systemd/src/SystemdLifetime.netcoreapp.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace Microsoft.Extensions.Hosting.Systemd
88
{
99
public partial class SystemdLifetime
1010
{
11-
private PosixSignalRegistration _sigTermRegistration;
11+
private PosixSignalRegistration? _sigTermRegistration;
1212

1313
private partial void RegisterShutdownHandlers()
1414
{

src/libraries/Microsoft.Extensions.Hosting.Systemd/src/SystemdNotifier.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ public class SystemdNotifier : ISystemdNotifier
1212
{
1313
private const string NOTIFY_SOCKET = "NOTIFY_SOCKET";
1414

15-
private readonly string _socketPath;
15+
private readonly string? _socketPath;
1616

1717
public SystemdNotifier() :
1818
this(GetNotifySocketPath())
1919
{ }
2020

2121
// For testing
22-
internal SystemdNotifier(string socketPath)
22+
internal SystemdNotifier(string? socketPath)
2323
{
2424
_socketPath = socketPath;
2525
}
@@ -37,7 +37,7 @@ public void Notify(ServiceState state)
3737

3838
using (var socket = new Socket(AddressFamily.Unix, SocketType.Dgram, ProtocolType.Unspecified))
3939
{
40-
var endPoint = new UnixDomainSocketEndPoint(_socketPath);
40+
var endPoint = new UnixDomainSocketEndPoint(_socketPath!);
4141
socket.Connect(endPoint);
4242

4343
// It's safe to do a non-blocking call here: messages sent here are much
@@ -46,9 +46,9 @@ public void Notify(ServiceState state)
4646
}
4747
}
4848

49-
private static string GetNotifySocketPath()
49+
private static string? GetNotifySocketPath()
5050
{
51-
string socketPath = Environment.GetEnvironmentVariable(NOTIFY_SOCKET);
51+
string? socketPath = Environment.GetEnvironmentVariable(NOTIFY_SOCKET);
5252

5353
if (string.IsNullOrEmpty(socketPath))
5454
{

0 commit comments

Comments
 (0)