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

Annotate System.Net.NameResolution for nullable reference types #32011

Merged
merged 1 commit into from
Feb 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable enable
using System;
using System.Net.Sockets;
using System.Runtime.InteropServices;
Expand All @@ -20,7 +21,7 @@ internal static partial class Winsock
[DllImport(Libraries.Ws2_32, ExactSpelling = true, CharSet = CharSet.Unicode, SetLastError = true)]
internal static extern unsafe int GetAddrInfoExW(
[In] string pName,
[In] string pServiceName,
[In] string? pServiceName,
[In] int dwNamespace,
[In] IntPtr lpNspId,
[In] AddressInfoEx* pHints,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable enable
using System;
using System.Net.Sockets;
using System.Runtime.InteropServices;
Expand All @@ -13,7 +14,7 @@ internal static partial class Winsock
[DllImport(Interop.Libraries.Ws2_32, ExactSpelling = true, CharSet = CharSet.Unicode, BestFitMapping = false, ThrowOnUnmappableChar = true, SetLastError = true)]
internal static extern unsafe int GetAddrInfoW(
[In] string pNameName,
[In] string pServiceName,
[In] string? pServiceName,
[In] AddressInfo* pHints,
[Out] AddressInfo** ppResult);

Expand Down
3 changes: 2 additions & 1 deletion src/libraries/Common/src/System/Net/DebugSafeHandle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable enable
using Microsoft.Win32.SafeHandles;

namespace System.Net
Expand All @@ -13,7 +14,7 @@ namespace System.Net
//
internal abstract class DebugSafeHandle : SafeHandleZeroOrMinusOneIsInvalid
{
private string _trace;
private string? _trace;

protected DebugSafeHandle(bool ownsHandle) : base(ownsHandle)
{
Expand Down
3 changes: 2 additions & 1 deletion src/libraries/Common/src/System/Net/InternalException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable enable
namespace System.Net
{
internal sealed class InternalException : Exception
{
private readonly object _unexpectedValue;
private readonly object? _unexpectedValue;

internal InternalException()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable enable
using System.Net.Sockets;

namespace System.Net.Internals
Expand All @@ -10,7 +11,7 @@ internal static partial class SocketExceptionFactory
{
private sealed class ExtendedSocketException : SocketException
{
private readonly EndPoint _endPoint;
private readonly EndPoint? _endPoint;

public ExtendedSocketException(int errorCode, EndPoint endPoint)
: base(errorCode)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,21 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable enable
using System.Collections.Generic;

namespace System.Net
{
internal static class DebugThreadTracking
{
[ThreadStatic]
private static Stack<ThreadKinds> t_threadKindStack;
private static Stack<ThreadKinds>? t_threadKindStack;

private static Stack<ThreadKinds> ThreadKindStack => t_threadKindStack ?? (t_threadKindStack = new Stack<ThreadKinds>());

internal static ThreadKinds CurrentThreadKind => ThreadKindStack.Count > 0 ? ThreadKindStack.Peek() : ThreadKinds.Other;

internal static IDisposable SetThreadKind(ThreadKinds kind)
internal static IDisposable? SetThreadKind(ThreadKinds kind)
{
if ((kind & ThreadKinds.SourceMask) != ThreadKinds.Unknown)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public class Keywords
/// <param name="formattableString">A description of the entrance, including any arguments to the call.</param>
/// <param name="memberName">The calling member.</param>
[NonEvent]
public static void Enter(object thisOrContextObject, FormattableString? formattableString = null, [CallerMemberName] string? memberName = null)
public static void Enter(object? thisOrContextObject, FormattableString? formattableString = null, [CallerMemberName] string? memberName = null)
{
DebugValidateArg(thisOrContextObject);
DebugValidateArg(formattableString);
Expand All @@ -112,7 +112,7 @@ public static void Enter(object thisOrContextObject, FormattableString? formatta
/// <param name="arg0">The object to log.</param>
/// <param name="memberName">The calling member.</param>
[NonEvent]
public static void Enter(object thisOrContextObject, object arg0, [CallerMemberName] string? memberName = null)
public static void Enter(object? thisOrContextObject, object arg0, [CallerMemberName] string? memberName = null)
{
DebugValidateArg(thisOrContextObject);
DebugValidateArg(arg0);
Expand All @@ -125,7 +125,7 @@ public static void Enter(object thisOrContextObject, object arg0, [CallerMemberN
/// <param name="arg1">The second object to log.</param>
/// <param name="memberName">The calling member.</param>
[NonEvent]
public static void Enter(object thisOrContextObject, object arg0, object arg1, [CallerMemberName] string? memberName = null)
public static void Enter(object? thisOrContextObject, object arg0, object arg1, [CallerMemberName] string? memberName = null)
{
DebugValidateArg(thisOrContextObject);
DebugValidateArg(arg0);
Expand All @@ -140,7 +140,7 @@ public static void Enter(object thisOrContextObject, object arg0, object arg1, [
/// <param name="arg2">The third object to log.</param>
/// <param name="memberName">The calling member.</param>
[NonEvent]
public static void Enter(object thisOrContextObject, object arg0, object arg1, object arg2, [CallerMemberName] string? memberName = null)
public static void Enter(object? thisOrContextObject, object arg0, object arg1, object arg2, [CallerMemberName] string? memberName = null)
{
DebugValidateArg(thisOrContextObject);
DebugValidateArg(arg0);
Expand All @@ -160,7 +160,7 @@ private void Enter(string thisOrContextObject, string? memberName, string parame
/// <param name="formattableString">A description of the exit operation, including any return values.</param>
/// <param name="memberName">The calling member.</param>
[NonEvent]
public static void Exit(object thisOrContextObject, FormattableString? formattableString = null, [CallerMemberName] string? memberName = null)
public static void Exit(object? thisOrContextObject, FormattableString? formattableString = null, [CallerMemberName] string? memberName = null)
{
DebugValidateArg(thisOrContextObject);
DebugValidateArg(formattableString);
Expand All @@ -172,7 +172,7 @@ public static void Exit(object thisOrContextObject, FormattableString? formattab
/// <param name="arg0">A return value from the member.</param>
/// <param name="memberName">The calling member.</param>
[NonEvent]
public static void Exit(object thisOrContextObject, object arg0, [CallerMemberName] string? memberName = null)
public static void Exit(object? thisOrContextObject, object arg0, [CallerMemberName] string? memberName = null)
{
DebugValidateArg(thisOrContextObject);
DebugValidateArg(arg0);
Expand All @@ -185,7 +185,7 @@ public static void Exit(object thisOrContextObject, object arg0, [CallerMemberNa
/// <param name="arg1">A second return value from the member.</param>
/// <param name="memberName">The calling member.</param>
[NonEvent]
public static void Exit(object thisOrContextObject, object arg0, object arg1, [CallerMemberName] string? memberName = null)
public static void Exit(object? thisOrContextObject, object arg0, object arg1, [CallerMemberName] string? memberName = null)
{
DebugValidateArg(thisOrContextObject);
DebugValidateArg(arg0);
Expand All @@ -204,7 +204,7 @@ private void Exit(string thisOrContextObject, string? memberName, string? result
/// <param name="formattableString">The message to be logged.</param>
/// <param name="memberName">The calling member.</param>
[NonEvent]
public static void Info(object thisOrContextObject, FormattableString? formattableString = null, [CallerMemberName] string? memberName = null)
public static void Info(object? thisOrContextObject, FormattableString? formattableString = null, [CallerMemberName] string? memberName = null)
{
DebugValidateArg(thisOrContextObject);
DebugValidateArg(formattableString);
Expand All @@ -216,7 +216,7 @@ public static void Info(object thisOrContextObject, FormattableString? formattab
/// <param name="message">The message to be logged.</param>
/// <param name="memberName">The calling member.</param>
[NonEvent]
public static void Info(object thisOrContextObject, object message, [CallerMemberName] string? memberName = null)
public static void Info(object? thisOrContextObject, object? message, [CallerMemberName] string? memberName = null)
{
DebugValidateArg(thisOrContextObject);
DebugValidateArg(message);
Expand All @@ -234,7 +234,7 @@ private void Info(string thisOrContextObject, string? memberName, string? messag
/// <param name="formattableString">The message to be logged.</param>
/// <param name="memberName">The calling member.</param>
[NonEvent]
public static void Error(object thisOrContextObject, FormattableString formattableString, [CallerMemberName] string? memberName = null)
public static void Error(object? thisOrContextObject, FormattableString formattableString, [CallerMemberName] string? memberName = null)
{
DebugValidateArg(thisOrContextObject);
DebugValidateArg(formattableString);
Expand All @@ -246,7 +246,7 @@ public static void Error(object thisOrContextObject, FormattableString formattab
/// <param name="message">The message to be logged.</param>
/// <param name="memberName">The calling member.</param>
[NonEvent]
public static void Error(object thisOrContextObject, object message, [CallerMemberName] string? memberName = null)
public static void Error(object? thisOrContextObject, object message, [CallerMemberName] string? memberName = null)
{
DebugValidateArg(thisOrContextObject);
DebugValidateArg(message);
Expand All @@ -264,7 +264,7 @@ private void ErrorMessage(string thisOrContextObject, string? memberName, string
/// <param name="formattableString">The message to be logged.</param>
/// <param name="memberName">The calling member.</param>
[NonEvent]
public static void Fail(object thisOrContextObject, FormattableString formattableString, [CallerMemberName] string? memberName = null)
public static void Fail(object? thisOrContextObject, FormattableString formattableString, [CallerMemberName] string? memberName = null)
{
// Don't call DebugValidateArg on args, as we expect Fail to be used in assert/failure situations
// that should never happen in production, and thus we don't care about extra costs.
Expand All @@ -278,7 +278,7 @@ public static void Fail(object thisOrContextObject, FormattableString formattabl
/// <param name="message">The message to be logged.</param>
/// <param name="memberName">The calling member.</param>
[NonEvent]
public static void Fail(object thisOrContextObject, object message, [CallerMemberName] string? memberName = null)
public static void Fail(object? thisOrContextObject, object message, [CallerMemberName] string? memberName = null)
{
// Don't call DebugValidateArg on args, as we expect Fail to be used in assert/failure situations
// that should never happen in production, and thus we don't care about extra costs.
Expand All @@ -298,7 +298,7 @@ private void CriticalFailure(string thisOrContextObject, string? memberName, str
/// <param name="buffer">The buffer to be logged.</param>
/// <param name="memberName">The calling member.</param>
[NonEvent]
public static void DumpBuffer(object thisOrContextObject, byte[] buffer, [CallerMemberName] string? memberName = null)
public static void DumpBuffer(object? thisOrContextObject, byte[] buffer, [CallerMemberName] string? memberName = null)
{
DumpBuffer(thisOrContextObject, buffer, 0, buffer.Length, memberName);
}
Expand All @@ -310,7 +310,7 @@ public static void DumpBuffer(object thisOrContextObject, byte[] buffer, [Caller
/// <param name="count">The number of bytes to log.</param>
/// <param name="memberName">The calling member.</param>
[NonEvent]
public static void DumpBuffer(object thisOrContextObject, byte[] buffer, int offset, int count, [CallerMemberName] string? memberName = null)
public static void DumpBuffer(object? thisOrContextObject, byte[] buffer, int offset, int count, [CallerMemberName] string? memberName = null)
{
if (IsEnabled)
{
Expand Down Expand Up @@ -339,7 +339,7 @@ public static void DumpBuffer(object thisOrContextObject, byte[] buffer, int off
/// <param name="count">The number of bytes to log.</param>
/// <param name="memberName">The calling member.</param>
[NonEvent]
public static unsafe void DumpBuffer(object thisOrContextObject, IntPtr bufferPtr, int count, [CallerMemberName] string? memberName = null)
public static unsafe void DumpBuffer(object? thisOrContextObject, IntPtr bufferPtr, int count, [CallerMemberName] string? memberName = null)
{
Debug.Assert(bufferPtr != IntPtr.Zero);
Debug.Assert(count >= 0);
Expand Down Expand Up @@ -379,7 +379,7 @@ public static void Associate(object first, object second, [CallerMemberName] str
/// <param name="second">The second object.</param>
/// <param name="memberName">The calling member.</param>
[NonEvent]
public static void Associate(object thisOrContextObject, object first, object second, [CallerMemberName] string? memberName = null)
public static void Associate(object? thisOrContextObject, object first, object second, [CallerMemberName] string? memberName = null)
{
DebugValidateArg(thisOrContextObject);
DebugValidateArg(first);
Expand All @@ -395,7 +395,7 @@ private void Associate(string thisOrContextObject, string? memberName, string fi

#region Helpers
[Conditional("DEBUG_NETEVENTSOURCE_MISUSE")]
private static void DebugValidateArg(object arg)
private static void DebugValidateArg(object? arg)
{
if (!IsEnabled)
{
Expand All @@ -414,7 +414,7 @@ private static void DebugValidateArg(FormattableString? arg)
Log.IsEnabled();

[NonEvent]
public static string IdOf(object value) => value != null ? value.GetType().Name + "#" + GetHashCode(value) : NullInstance;
public static string IdOf(object? value) => value != null ? value.GetType().Name + "#" + GetHashCode(value) : NullInstance;

[NonEvent]
public static int GetHashCode(object value) => value?.GetHashCode() ?? 0;
Expand Down Expand Up @@ -498,7 +498,7 @@ private static string Format(FormattableString s)
#region Custom WriteEvent overloads

[NonEvent]
private unsafe void WriteEvent(int eventId, string arg1, string arg2, string arg3, string arg4)
private unsafe void WriteEvent(int eventId, string? arg1, string? arg2, string? arg3, string? arg4)
{
if (IsEnabled())
{
Expand Down Expand Up @@ -542,7 +542,7 @@ private unsafe void WriteEvent(int eventId, string arg1, string arg2, string arg
}

[NonEvent]
private unsafe void WriteEvent(int eventId, string arg1, string arg2, byte[] arg3)
private unsafe void WriteEvent(int eventId, string? arg1, string? arg2, byte[]? arg3)
{
if (IsEnabled())
{
Expand Down Expand Up @@ -585,7 +585,7 @@ private unsafe void WriteEvent(int eventId, string arg1, string arg2, byte[] arg
}

[NonEvent]
private unsafe void WriteEvent(int eventId, string arg1, int arg2, int arg3, int arg4)
private unsafe void WriteEvent(int eventId, string? arg1, int arg2, int arg3, int arg4)
{
if (IsEnabled())
{
Expand Down Expand Up @@ -623,7 +623,7 @@ private unsafe void WriteEvent(int eventId, string arg1, int arg2, int arg3, int
}

[NonEvent]
private unsafe void WriteEvent(int eventId, string arg1, int arg2, string arg3)
private unsafe void WriteEvent(int eventId, string? arg1, int arg2, string? arg3)
{
if (IsEnabled())
{
Expand Down Expand Up @@ -658,7 +658,7 @@ private unsafe void WriteEvent(int eventId, string arg1, int arg2, string arg3)
}

[NonEvent]
private unsafe void WriteEvent(int eventId, string arg1, string arg2, int arg3)
private unsafe void WriteEvent(int eventId, string? arg1, string? arg2, int arg3)
{
if (IsEnabled())
{
Expand Down Expand Up @@ -693,7 +693,7 @@ private unsafe void WriteEvent(int eventId, string arg1, string arg2, int arg3)
}

[NonEvent]
private unsafe void WriteEvent(int eventId, string arg1, string arg2, string arg3, int arg4)
private unsafe void WriteEvent(int eventId, string? arg1, string? arg2, string? arg3, int arg4)
{
if (IsEnabled())
{
Expand Down
Loading