Skip to content

Commit

Permalink
Merge pull request #41348 from carlossanlop/nullabilityBackport50
Browse files Browse the repository at this point in the history
[release/5.0] Backport nullability annotations to release/5.0
  • Loading branch information
carlossanlop authored Sep 1, 2020
2 parents 7b4014e + 74dc622 commit fe9059e
Show file tree
Hide file tree
Showing 902 changed files with 9,862 additions and 9,773 deletions.
38 changes: 19 additions & 19 deletions src/libraries/Common/src/Interop/Windows/HttpApi/Interop.HttpApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ protected override bool ReleaseHandle()
[DllImport(Libraries.HttpApi, SetLastError = true)]
internal static extern unsafe uint HttpReceiveClientCertificate(SafeHandle requestQueueHandle, ulong connectionId, uint flags, byte* pSslClientCertInfo, uint sslClientCertInfoSize, uint* pBytesReceived, NativeOverlapped* pOverlapped);

internal static readonly string[] HttpVerbs = new string[]
internal static readonly string?[] HttpVerbs = new string?[]
{
null,
"Unknown",
Expand Down Expand Up @@ -661,9 +661,9 @@ internal static int IndexOfKnownHeader(string headerName)
}
}

private static unsafe string GetKnownHeader(HTTP_REQUEST* request, long fixup, int headerIndex)
private static unsafe string? GetKnownHeader(HTTP_REQUEST* request, long fixup, int headerIndex)
{
string header = null;
string? header = null;

HTTP_KNOWN_HEADER* pKnownHeader = (&request->Headers.KnownHeaders) + headerIndex;

Expand All @@ -683,14 +683,14 @@ private static unsafe string GetKnownHeader(HTTP_REQUEST* request, long fixup, i
return header;
}

internal static unsafe string GetKnownHeader(HTTP_REQUEST* request, int headerIndex)
internal static unsafe string? GetKnownHeader(HTTP_REQUEST* request, int headerIndex)
{
return GetKnownHeader(request, 0, headerIndex);
}

private static unsafe string GetVerb(HTTP_REQUEST* request, long fixup)
private static unsafe string? GetVerb(HTTP_REQUEST* request, long fixup)
{
string verb = null;
string? verb = null;

if ((int)request->Verb > (int)HTTP_VERB.HttpVerbUnknown && (int)request->Verb < (int)HTTP_VERB.HttpVerbMaximum)
{
Expand All @@ -704,12 +704,12 @@ private static unsafe string GetVerb(HTTP_REQUEST* request, long fixup)
return verb;
}

internal static unsafe string GetVerb(HTTP_REQUEST* request)
internal static unsafe string? GetVerb(HTTP_REQUEST* request)
{
return GetVerb(request, 0);
}

internal static unsafe string GetVerb(IntPtr memoryBlob, IntPtr originalAddress)
internal static unsafe string? GetVerb(IntPtr memoryBlob, IntPtr originalAddress)
{
return GetVerb((HTTP_REQUEST*)memoryBlob.ToPointer(), (byte*)memoryBlob - (byte*)originalAddress);
}
Expand Down Expand Up @@ -834,17 +834,17 @@ internal static unsafe HTTP_VERB GetKnownVerb(IntPtr memoryBlob, IntPtr original
return verb;
}

internal static unsafe IPEndPoint GetRemoteEndPoint(IntPtr memoryBlob, IntPtr originalAddress)
internal static unsafe IPEndPoint? GetRemoteEndPoint(IntPtr memoryBlob, IntPtr originalAddress)
{
SocketAddress v4address = new SocketAddress(AddressFamily.InterNetwork, IPv4AddressSize);
SocketAddress v6address = new SocketAddress(AddressFamily.InterNetworkV6, IPv6AddressSize);
SocketAddress? v4address = new SocketAddress(AddressFamily.InterNetwork, IPv4AddressSize);
SocketAddress? v6address = new SocketAddress(AddressFamily.InterNetworkV6, IPv6AddressSize);

byte* pMemoryBlob = (byte*)memoryBlob;
HTTP_REQUEST* request = (HTTP_REQUEST*)pMemoryBlob;
IntPtr address = request->Address.pRemoteAddress != null ? (IntPtr)(pMemoryBlob - (byte*)originalAddress + (byte*)request->Address.pRemoteAddress) : IntPtr.Zero;
CopyOutAddress(address, ref v4address, ref v6address);

IPEndPoint endpoint = null;
IPEndPoint? endpoint = null;
if (v4address != null)
{
endpoint = new IPEndPoint(IPAddress.Any, IPEndPoint.MinPort).Create(v4address) as IPEndPoint;
Expand All @@ -857,17 +857,17 @@ internal static unsafe IPEndPoint GetRemoteEndPoint(IntPtr memoryBlob, IntPtr or
return endpoint;
}

internal static unsafe IPEndPoint GetLocalEndPoint(IntPtr memoryBlob, IntPtr originalAddress)
internal static unsafe IPEndPoint? GetLocalEndPoint(IntPtr memoryBlob, IntPtr originalAddress)
{
SocketAddress v4address = new SocketAddress(AddressFamily.InterNetwork, IPv4AddressSize);
SocketAddress v6address = new SocketAddress(AddressFamily.InterNetworkV6, IPv6AddressSize);
SocketAddress? v4address = new SocketAddress(AddressFamily.InterNetwork, IPv4AddressSize);
SocketAddress? v6address = new SocketAddress(AddressFamily.InterNetworkV6, IPv6AddressSize);

byte* pMemoryBlob = (byte*)memoryBlob;
HTTP_REQUEST* request = (HTTP_REQUEST*)pMemoryBlob;
IntPtr address = request->Address.pLocalAddress != null ? (IntPtr)(pMemoryBlob - (byte*)originalAddress + (byte*)request->Address.pLocalAddress) : IntPtr.Zero;
CopyOutAddress(address, ref v4address, ref v6address);

IPEndPoint endpoint = null;
IPEndPoint? endpoint = null;
if (v4address != null)
{
endpoint = s_any.Create(v4address) as IPEndPoint;
Expand All @@ -880,7 +880,7 @@ internal static unsafe IPEndPoint GetLocalEndPoint(IntPtr memoryBlob, IntPtr ori
return endpoint;
}

private static unsafe void CopyOutAddress(IntPtr address, ref SocketAddress v4address, ref SocketAddress v6address)
private static unsafe void CopyOutAddress(IntPtr address, ref SocketAddress? v4address, ref SocketAddress? v6address)
{
if (address != IntPtr.Zero)
{
Expand All @@ -890,7 +890,7 @@ private static unsafe void CopyOutAddress(IntPtr address, ref SocketAddress v4ad
v6address = null;
for (int index = 2; index < IPv4AddressSize; index++)
{
v4address[index] = ((byte*)address)[index];
v4address![index] = ((byte*)address)[index];
}
return;
}
Expand All @@ -899,7 +899,7 @@ private static unsafe void CopyOutAddress(IntPtr address, ref SocketAddress v4ad
v4address = null;
for (int index = 2; index < IPv6AddressSize; index++)
{
v6address[index] = ((byte*)address)[index];
v6address![index] = ((byte*)address)[index];
}
return;
}
Expand Down
1 change: 1 addition & 0 deletions src/libraries/Common/src/SkipLocalsInit.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#nullable disable
// Used to indicate to the compiler that the .locals init flag should not be set in method headers.
[module: System.Runtime.CompilerServices.SkipLocalsInit]
1 change: 1 addition & 0 deletions src/libraries/Common/src/System/CSharpHelpers.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#nullable disable
using System.Collections.Generic;
using System.Globalization;

Expand Down
2 changes: 1 addition & 1 deletion src/libraries/Common/src/System/CodeDom/CodeObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class CodeObject
internal class CodeObject
#endif
{
private IDictionary _userData;
private IDictionary? _userData;

public CodeObject() { }

Expand Down
16 changes: 8 additions & 8 deletions src/libraries/Common/src/System/CodeDom/CodeTypeReference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ public class CodeTypeReference : CodeObject
internal class CodeTypeReference : CodeObject
#endif
{
private string _baseType;
private string? _baseType;
private readonly bool _isInterface;
private CodeTypeReferenceCollection _typeArguments;
private CodeTypeReferenceCollection? _typeArguments;
private bool _needsFixup;

public CodeTypeReference()
Expand All @@ -50,7 +50,7 @@ public CodeTypeReference(Type type)
if (type.IsArray)
{
ArrayRank = type.GetArrayRank();
ArrayElementType = new CodeTypeReference(type.GetElementType());
ArrayElementType = new CodeTypeReference(type.GetElementType()!);
_baseType = null;
}
else
Expand Down Expand Up @@ -86,7 +86,7 @@ private void InitializeFromType(Type type)
Type currentType = type;
while (currentType.IsNested)
{
currentType = currentType.DeclaringType;
currentType = currentType.DeclaringType!;
_baseType = currentType.Name + "+" + _baseType;
}

Expand Down Expand Up @@ -116,17 +116,17 @@ private void InitializeFromType(Type type)
}
}

private void Initialize(string typeName)
private void Initialize(string? typeName)
{
Initialize(typeName, Options);
}

private void Initialize(string typeName, CodeTypeReferenceOptions options)
private void Initialize(string? typeName, CodeTypeReferenceOptions options)
{
Options = options;
if (string.IsNullOrEmpty(typeName))
{
typeName = typeof(void).FullName;
typeName = typeof(void).FullName!;
_baseType = typeName;
ArrayRank = 0;
ArrayElementType = null;
Expand Down Expand Up @@ -303,7 +303,7 @@ public CodeTypeReference(CodeTypeReference arrayType, int rank)
ArrayElementType = arrayType;
}

public CodeTypeReference ArrayElementType { get; set; }
public CodeTypeReference? ArrayElementType { get; set; }

public int ArrayRank { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public CodeTypeReferenceCollection(CodeTypeReference[] value)

public CodeTypeReference this[int index]
{
get { return ((CodeTypeReference)(List[index])); }
get { return ((CodeTypeReference)(List[index]!)); }
set { List[index] = value; }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ private DataTable ExecuteCommand(DataRow requestedCollectionRow, string?[]? rest
Locale = CultureInfo.InvariantCulture
};

schemaTable = reader.GetSchemaTable();
schemaTable = reader.GetSchemaTable()!;
foreach (DataRow row in schemaTable.Rows)
{
resultTable.Columns.Add(row["ColumnName"] as string, (Type)row["DataType"]);
Expand Down
1 change: 1 addition & 0 deletions src/libraries/Common/src/System/HexConverter.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#nullable disable
using System.Diagnostics;
using System.Runtime.CompilerServices;

Expand Down
1 change: 1 addition & 0 deletions src/libraries/Common/src/System/Marvin.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#nullable disable
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
Expand Down
20 changes: 9 additions & 11 deletions src/libraries/System.Data.Common/ref/System.Data.Common.cs
Original file line number Diff line number Diff line change
Expand Up @@ -863,7 +863,7 @@ public override void Close() { }
public override System.Type GetProviderSpecificFieldType(int ordinal) { throw null; }
public override object GetProviderSpecificValue(int ordinal) { throw null; }
public override int GetProviderSpecificValues(object[] values) { throw null; }
public override System.Data.DataTable GetSchemaTable() { throw null; }
public override System.Data.DataTable? GetSchemaTable() { throw null; }
public override string GetString(int ordinal) { throw null; }
public override object GetValue(int ordinal) { throw null; }
public override int GetValues(object[] values) { throw null; }
Expand Down Expand Up @@ -1247,7 +1247,7 @@ public partial interface IDataReader : System.Data.IDataRecord, System.IDisposab
bool IsClosed { get; }
int RecordsAffected { get; }
void Close();
System.Data.DataTable GetSchemaTable();
System.Data.DataTable? GetSchemaTable();
bool NextResult();
bool Read();
}
Expand Down Expand Up @@ -1948,7 +1948,7 @@ protected override void Dispose(bool disposing) { }
protected abstract string GetParameterName(int parameterOrdinal);
protected abstract string GetParameterName(string parameterName);
protected abstract string GetParameterPlaceholder(int parameterOrdinal);
protected virtual System.Data.DataTable GetSchemaTable(System.Data.Common.DbCommand sourceCommand) { throw null; }
protected virtual System.Data.DataTable? GetSchemaTable(System.Data.Common.DbCommand sourceCommand) { throw null; }
public System.Data.Common.DbCommand GetUpdateCommand() { throw null; }
public System.Data.Common.DbCommand GetUpdateCommand(bool useColumnsForParameterNames) { throw null; }
protected virtual System.Data.Common.DbCommand InitializeCommand(System.Data.Common.DbCommand? command) { throw null; }
Expand Down Expand Up @@ -2169,8 +2169,8 @@ protected virtual void Dispose(bool disposing) { }
public virtual object GetProviderSpecificValue(int ordinal) { throw null; }
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
public virtual int GetProviderSpecificValues(object[] values) { throw null; }
public virtual System.Data.DataTable GetSchemaTable() { throw null; }
public virtual System.Threading.Tasks.Task<System.Data.DataTable> GetSchemaTableAsync(System.Threading.CancellationToken cancellationToken = default) { throw null; }
public virtual System.Data.DataTable? GetSchemaTable() { throw null; }
public virtual System.Threading.Tasks.Task<System.Data.DataTable?> GetSchemaTableAsync(System.Threading.CancellationToken cancellationToken = default) { throw null; }
public virtual System.Threading.Tasks.Task<System.Collections.ObjectModel.ReadOnlyCollection<System.Data.Common.DbColumn>> GetColumnSchemaAsync(System.Threading.CancellationToken cancellationToken = default) { throw null; }
public virtual System.IO.Stream GetStream(int ordinal) { throw null; }
public abstract string GetString(int ordinal);
Expand Down Expand Up @@ -3536,7 +3536,6 @@ public enum StorageState
UnmanagedBuffer = 2,
}
}
#nullable disable
namespace System.Xml
{
[System.ObsoleteAttribute("XmlDataDocument class will be removed in a future release.")]
Expand All @@ -3546,17 +3545,16 @@ public XmlDataDocument() { }
public XmlDataDocument(System.Data.DataSet dataset) { }
public System.Data.DataSet DataSet { get { throw null; } }
public override System.Xml.XmlNode CloneNode(bool deep) { throw null; }
public override System.Xml.XmlElement CreateElement(string prefix, string localName, string namespaceURI) { throw null; }
public override System.Xml.XmlElement CreateElement(string? prefix, string localName, string? namespaceURI) { throw null; }
public override System.Xml.XmlEntityReference CreateEntityReference(string name) { throw null; }
protected override System.Xml.XPath.XPathNavigator CreateNavigator(System.Xml.XmlNode node) { throw null; }
public override System.Xml.XmlElement GetElementById(string elemId) { throw null; }
protected override System.Xml.XPath.XPathNavigator? CreateNavigator(System.Xml.XmlNode node) { throw null; }
public override System.Xml.XmlElement? GetElementById(string elemId) { throw null; }
public System.Xml.XmlElement GetElementFromRow(System.Data.DataRow r) { throw null; }
public override System.Xml.XmlNodeList GetElementsByTagName(string name) { throw null; }
public System.Data.DataRow GetRowFromElement(System.Xml.XmlElement e) { throw null; }
public System.Data.DataRow? GetRowFromElement(System.Xml.XmlElement? e) { throw null; }
public override void Load(System.IO.Stream inStream) { }
public override void Load(System.IO.TextReader txtReader) { }
public override void Load(string filename) { }
public override void Load(System.Xml.XmlReader reader) { }
}
}
#nullable enable
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ private void BuildCache(bool closeConnection, DataRow? dataRow, bool useColumnsF
ADP.BuildSchemaTableInfoTableNames(srcColumnNames);
}

protected virtual DataTable GetSchemaTable(DbCommand sourceCommand)
protected virtual DataTable? GetSchemaTable(DbCommand sourceCommand)
{
using (IDataReader dataReader = sourceCommand.ExecuteReader(CommandBehavior.SchemaOnly | CommandBehavior.KeyInfo))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,13 @@ public virtual ValueTask DisposeAsync()

/// <summary>
/// Returns a <see cref="DataTable" /> that describes the column metadata of the ><see cref="DbDataReader" />.
///
/// Returns <see langword="null" /> if the executed command returned no resultset, or after
/// <see cref="NextResult" /> returns <see langword="false" />.
/// </summary>
/// <returns>A <see cref="DataTable" /> that describes the column metadata.</returns>
/// <exception cref="InvalidOperationException">The <see cref="DbDataReader" /> is closed.</exception>
/// <exception cref="IndexOutOfRangeException">The column index is out of range.</exception>
/// <exception cref="NotSupportedException">.NET Core only: This member is not supported.</exception>
public virtual DataTable GetSchemaTable()
public virtual DataTable? GetSchemaTable()
{
throw new NotSupportedException();
}
Expand All @@ -97,11 +98,11 @@ public virtual DataTable GetSchemaTable()
/// </summary>
/// <param name="cancellationToken">The cancellation instruction.</param>
/// <returns>A task representing the asynchronous operation.</returns>
public virtual Task<DataTable> GetSchemaTableAsync(CancellationToken cancellationToken = default)
public virtual Task<DataTable?> GetSchemaTableAsync(CancellationToken cancellationToken = default)
{
if (cancellationToken.IsCancellationRequested)
{
return Task.FromCanceled<DataTable>(cancellationToken);
return Task.FromCanceled<DataTable?>(cancellationToken);
}

try
Expand All @@ -110,7 +111,7 @@ public virtual Task<DataTable> GetSchemaTableAsync(CancellationToken cancellatio
}
catch (Exception e)
{
return Task.FromException<DataTable>(e);
return Task.FromException<DataTable?>(e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,15 @@ public static bool CanGetColumnSchema(this DbDataReader reader)
private static ReadOnlyCollection<DbColumn> GetColumnSchemaCompatibility(DbDataReader reader)
{
var columnSchema = new List<DbColumn>();
DataTable schemaTable = reader.GetSchemaTable();
DataColumnCollection schemaTableColumns = schemaTable.Columns;
foreach (DataRow row in schemaTable.Rows)
DataTable? schemaTable = reader.GetSchemaTable();
if (schemaTable != null)
{
Debug.Assert(row != null);
columnSchema.Add(new DataRowDbColumn(row, schemaTableColumns));
DataColumnCollection schemaTableColumns = schemaTable.Columns;
foreach (DataRow row in schemaTable.Rows)
{
Debug.Assert(row != null);
columnSchema.Add(new DataRowDbColumn(row, schemaTableColumns));
}
}
return new ReadOnlyCollection<DbColumn>(columnSchema);
}
Expand Down
Loading

0 comments on commit fe9059e

Please sign in to comment.