diff --git a/src/coreclr/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComActivator.cs b/src/coreclr/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComActivator.cs index db8d4ead4659b9..77f64abd1b42c0 100644 --- a/src/coreclr/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComActivator.cs +++ b/src/coreclr/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComActivator.cs @@ -203,7 +203,6 @@ private static void ClassRegistrationScenarioForType(ComActivationContext cxt, b // Finally validate signature ReadOnlySpan methParams = method.GetParametersAsSpan(); if (method.ReturnType != typeof(void) - || methParams == null || methParams.Length != 1 || (methParams[0].ParameterType != typeof(string) && methParams[0].ParameterType != typeof(Type))) { diff --git a/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/DynamicILGenerator.cs b/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/DynamicILGenerator.cs index 2b695f1baf5b0f..327113c63f9a3c 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/DynamicILGenerator.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/DynamicILGenerator.cs @@ -417,7 +417,7 @@ private int GetMemberRefToken(MethodInfo methodInfo, Type[]? optionalParameterTy throw new ArgumentException(SR.Argument_MustBeRuntimeMethodInfo, nameof(methodInfo)); ReadOnlySpan paramInfo = methodInfo.GetParametersAsSpan(); - if (paramInfo != null && paramInfo.Length != 0) + if (paramInfo.Length != 0) { parameterTypes = new Type[paramInfo.Length]; requiredCustomModifiers = new Type[parameterTypes.Length][]; diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/MethodInfos/CustomMethodInvoker.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/MethodInfos/CustomMethodInvoker.cs index fbf56e6e4603d2..f2c15681c288fe 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/MethodInfos/CustomMethodInvoker.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/MethodInfos/CustomMethodInvoker.cs @@ -36,7 +36,7 @@ public CustomMethodInvoker(Type thisType, Type[] parameterTypes, InvokerOptions if (!(thisObject == null && 0 != (_options & InvokerOptions.AllowNullThis))) ValidateThis(thisObject, _thisType.TypeHandle); - int argCount = (arguments != null) ? arguments.Length : 0; + int argCount = arguments.Length; if (argCount != _parameterTypes.Length) throw new TargetParameterCountException(); diff --git a/src/libraries/Common/src/Interop/OSX/System.Security.Cryptography.Native.Apple/Interop.SecKeyRef.macOS.cs b/src/libraries/Common/src/Interop/OSX/System.Security.Cryptography.Native.Apple/Interop.SecKeyRef.macOS.cs index e4bca886045c90..74f4ccd2fafb9f 100644 --- a/src/libraries/Common/src/Interop/OSX/System.Security.Cryptography.Native.Apple/Interop.SecKeyRef.macOS.cs +++ b/src/libraries/Common/src/Interop/OSX/System.Security.Cryptography.Native.Apple/Interop.SecKeyRef.macOS.cs @@ -3,6 +3,7 @@ using System; using System.Diagnostics; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Security.Cryptography; using System.Security.Cryptography.Apple; @@ -36,7 +37,7 @@ private static partial int AppleCryptoNative_SecKeyImportEphemeral( internal static SafeSecKeyRefHandle ImportEphemeralKey(ReadOnlySpan keyBlob, bool hasPrivateKey) { - Debug.Assert(keyBlob != null); + Debug.Assert(!Unsafe.IsNullRef(ref MemoryMarshal.GetReference(keyBlob))); SafeSecKeyRefHandle keyHandle; int osStatus; diff --git a/src/libraries/Common/src/System/Net/Http/aspnetcore/Http2/Hpack/Huffman.cs b/src/libraries/Common/src/System/Net/Http/aspnetcore/Http2/Hpack/Huffman.cs index b23b7e63529d8a..980bfbc3579995 100644 --- a/src/libraries/Common/src/System/Net/Http/aspnetcore/Http2/Hpack/Huffman.cs +++ b/src/libraries/Common/src/System/Net/Http/aspnetcore/Http2/Hpack/Huffman.cs @@ -677,7 +677,7 @@ public static int Decode(ReadOnlySpan src, ref byte[] dstArray) // see comments in GenerateDecodingLookupTree() describing decoding table Span dst = dstArray; - Debug.Assert(dst != null && dst.Length > 0); + Debug.Assert(dst.Length > 0); ushort[] decodingTree = s_decodingTree; diff --git a/src/libraries/Common/src/System/Number.Parsing.Common.cs b/src/libraries/Common/src/System/Number.Parsing.Common.cs index 16e9f777f3464b..e43cbe14c29226 100644 --- a/src/libraries/Common/src/System/Number.Parsing.Common.cs +++ b/src/libraries/Common/src/System/Number.Parsing.Common.cs @@ -336,7 +336,7 @@ internal enum ParsingStatus private static unsafe TChar* MatchChars(TChar* p, TChar* pEnd, ReadOnlySpan value) where TChar : unmanaged, IUtfChar { - Debug.Assert((p != null) && (pEnd != null) && (p <= pEnd) && (value != null)); + Debug.Assert((p != null) && (pEnd != null) && (p <= pEnd)); fixed (TChar* stringPointer = &MemoryMarshal.GetReference(value)) { diff --git a/src/libraries/System.IO.FileSystem.Watcher/src/System/IO/FileSystemWatcher.Linux.cs b/src/libraries/System.IO.FileSystem.Watcher/src/System/IO/FileSystemWatcher.Linux.cs index 65dcefea25dafb..b09e0197e04471 100644 --- a/src/libraries/System.IO.FileSystem.Watcher/src/System/IO/FileSystemWatcher.Linux.cs +++ b/src/libraries/System.IO.FileSystem.Watcher/src/System/IO/FileSystemWatcher.Linux.cs @@ -720,9 +720,9 @@ private bool ProcessEvent(NotifyEvent nextEvent, ref ReadOnlySpan previous break; case Interop.Sys.NotifyEvents.IN_MOVED_TO: - if (previousEventName != null) + if (!previousEventName.IsEmpty) { - // If the previous name from IN_MOVED_FROM is non-null, then this is a rename. + // If the previous name from IN_MOVED_FROM is non-empty, then this is a rename. watcher.NotifyRenameEventArgs(WatcherChangeTypes.Renamed, expandedName, previousEventName); } else diff --git a/src/libraries/System.IO.Packaging/src/System/IO/Packaging/ContentType.cs b/src/libraries/System.IO.Packaging/src/System/IO/Packaging/ContentType.cs index c6fe72e7f047df..894fd4826aa80d 100644 --- a/src/libraries/System.IO.Packaging/src/System/IO/Packaging/ContentType.cs +++ b/src/libraries/System.IO.Packaging/src/System/IO/Packaging/ContentType.cs @@ -351,8 +351,6 @@ private void ParseParameterAndValue(ReadOnlySpan parameterAndValue) /// private static int GetLengthOfParameterValue(ReadOnlySpan s, int startIndex) { - Debug.Assert(s != null); - int length; //if the parameter value does not start with a '"' then, diff --git a/src/libraries/System.Net.Primitives/src/System/Net/IPAddress.cs b/src/libraries/System.Net.Primitives/src/System/Net/IPAddress.cs index bdd381fc04901c..48f424407b400c 100644 --- a/src/libraries/System.Net.Primitives/src/System/Net/IPAddress.cs +++ b/src/libraries/System.Net.Primitives/src/System/Net/IPAddress.cs @@ -142,7 +142,6 @@ public IPAddress(ReadOnlySpan address, long scopeid) internal IPAddress(ReadOnlySpan numbers, uint scopeid) { - Debug.Assert(numbers != null); Debug.Assert(numbers.Length == NumberOfLabels); _numbers = numbers.ToArray(); diff --git a/src/libraries/System.Net.Primitives/src/System/Net/IPAddressParser.cs b/src/libraries/System.Net.Primitives/src/System/Net/IPAddressParser.cs index 964cd4308366ab..afe80e3cd5b829 100644 --- a/src/libraries/System.Net.Primitives/src/System/Net/IPAddressParser.cs +++ b/src/libraries/System.Net.Primitives/src/System/Net/IPAddressParser.cs @@ -67,7 +67,6 @@ private static unsafe bool TryParseIpv4(ReadOnlySpan ipSpan, out long addr private static unsafe bool TryParseIPv6(ReadOnlySpan ipSpan, Span numbers, int numbersLength, out uint scope) { - Debug.Assert(numbers != null); Debug.Assert(numbersLength >= IPAddressParserStatics.IPv6AddressShorts); int end = ipSpan.Length; diff --git a/src/libraries/System.Net.Sockets/src/System/Net/Sockets/SocketPal.Unix.cs b/src/libraries/System.Net.Sockets/src/System/Net/Sockets/SocketPal.Unix.cs index d2ac959e0b4c73..837743dfa34478 100644 --- a/src/libraries/System.Net.Sockets/src/System/Net/Sockets/SocketPal.Unix.cs +++ b/src/libraries/System.Net.Sockets/src/System/Net/Sockets/SocketPal.Unix.cs @@ -528,7 +528,6 @@ private static unsafe int SysReceiveMessageFrom( out SocketFlags receivedFlags, out IPPacketInformation ipPacketInformation, out Interop.Error errno) { Debug.Assert(socket.IsSocket); - Debug.Assert(socketAddress != null, "Expected non-null socketAddress"); int buffersCount = buffers.Count; bool allocOnStack = buffersCount <= IovStackThreshold; @@ -810,7 +809,6 @@ public static unsafe bool TryCompleteReceiveFrom(SafeSocketHandle socket, Span { sent = buffers != null ? SysSend(socket, flags, buffers, ref bufferIndex, ref offset, socketAddress, out errno) : - socketAddress == null ? SysSend(socket, flags, buffer, ref offset, ref count, out errno) : + socketAddress.IsEmpty ? SysSend(socket, flags, buffer, ref offset, ref count, out errno) : SysSend(socket, flags, buffer, ref offset, ref count, socketAddress, out errno); } } diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/TimeSpanFormat.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/TimeSpanFormat.cs index 4e11f14c80903b..8c8bea12bbf6b2 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/TimeSpanFormat.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/TimeSpanFormat.cs @@ -268,12 +268,11 @@ internal static unsafe bool TryFormatStandard(TimeSpan value, StandardFor // Write fraction and separator, if necessary if (fractionDigits != 0) { - Debug.Assert(format == StandardFormat.C || decimalSeparator != null); if (format == StandardFormat.C) { *p++ = TChar.CastFrom('.'); } - else if (decimalSeparator!.Length == 1) + else if (decimalSeparator.Length == 1) { *p++ = decimalSeparator[0]; } diff --git a/src/libraries/System.Private.CoreLib/src/System/Number.Formatting.cs b/src/libraries/System.Private.CoreLib/src/System/Number.Formatting.cs index 3bb61ebcf736f6..c8884036777343 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Number.Formatting.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Number.Formatting.cs @@ -3498,7 +3498,6 @@ private static unsafe void FormatFixed( { if (groupDigits != null) { - Debug.Assert(sGroup != null, "Must be null when groupDigits != null"); int groupSizeIndex = 0; // Index into the groupDigits array. int bufferSize = digPos; // The length of the result buffer string. int groupSize = 0; // The current group size. @@ -3583,7 +3582,6 @@ private static unsafe void FormatFixed( if (nMaxDigits > 0) { - Debug.Assert(sDecimal != null); vlb.Append(sDecimal); if ((digPos < 0) && (nMaxDigits > 0)) { diff --git a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/HashProviderCng.cs b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/HashProviderCng.cs index 831b846a74447e..36f4767e9939e6 100644 --- a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/HashProviderCng.cs +++ b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/HashProviderCng.cs @@ -39,7 +39,7 @@ internal HashProviderCng(string hashAlgId, ReadOnlySpan key, bool isHmac) // So keep hHash trapped in this scope to prevent (mis-)use of it. { SafeBCryptHashHandle hHash; - NTSTATUS ntStatus = Interop.BCrypt.BCryptCreateHash(_hAlgorithm, out hHash, IntPtr.Zero, 0, key, key == null ? 0 : key.Length, BCryptCreateHashFlags.BCRYPT_HASH_REUSABLE_FLAG); + NTSTATUS ntStatus = Interop.BCrypt.BCryptCreateHash(_hAlgorithm, out hHash, IntPtr.Zero, 0, key, key.Length, BCryptCreateHashFlags.BCRYPT_HASH_REUSABLE_FLAG); if (ntStatus == NTSTATUS.STATUS_INVALID_PARAMETER) { hHash.Dispose(); diff --git a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/CertificateRequest.cs b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/CertificateRequest.cs index c3084c964d7dc2..405d37188e3729 100644 --- a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/CertificateRequest.cs +++ b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/CertificateRequest.cs @@ -812,7 +812,7 @@ public X509Certificate2 Create( if (notAfter < notBefore) throw new ArgumentException(SR.Cryptography_CertReq_DatesReversed); - if (serialNumber == null || serialNumber.Length < 1) + if (serialNumber.Length < 1) throw new ArgumentException(SR.Arg_EmptyOrNullArray, nameof(serialNumber)); byte[] signatureAlgorithm = generator.GetSignatureAlgorithmIdentifier(HashAlgorithm); diff --git a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/X500NameEncoder.cs b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/X500NameEncoder.cs index d2509eca3c3da1..865b18e0951888 100644 --- a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/X500NameEncoder.cs +++ b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/X500NameEncoder.cs @@ -444,7 +444,6 @@ private static List ParseDistinguishedName( // then some whitespace. case ParseState.MaybeEndQuote: case ParseState.SeekComma: - Debug.Assert(tagOid != null); Debug.Assert(valueStart != -1); Debug.Assert(valueEnd != -1); diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Document/JsonDocument.Parse.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Document/JsonDocument.Parse.cs index e5719888d80a79..f9b1fffd4243b2 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Document/JsonDocument.Parse.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Document/JsonDocument.Parse.cs @@ -165,8 +165,6 @@ internal static JsonDocument ParseValue(Stream utf8Json, JsonDocumentOptions opt internal static JsonDocument ParseValue(ReadOnlySpan utf8Json, JsonDocumentOptions options) { - Debug.Assert(utf8Json != null); - byte[] owned = new byte[utf8Json.Length]; utf8Json.CopyTo(owned);