Closed
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
2 changes: 1 addition & 1 deletion eng/CodeAnalysis.ruleset
Original file line numberDiff line numberDiff line change
Expand Up@@ -106,7 +106,7 @@
<Rule Id="CA2200" Action="Warning" /> <!-- Rethrow to preserve stack details. -->
<Rule Id="CA2201" Action="None" /> <!-- Do not raise reserved exception types -->
<Rule Id="CA2207" Action="Warning" /> <!-- Initialize value type static fields inline -->
<Rule Id="CA2208" Action="None" /> <!-- Instantiate argument exceptions correctly -->
<Rule Id="CA2208" Action="Info" /> <!-- Instantiate argument exceptions correctly -->

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would have thought we wanted Warnings here (with everything fixed or suppressed by this PR)

@buyaa-nbuyaa-nApr 20, 2020

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have discussed to upgrade severity level from hidden to info, so I thought I should make it same here, but yes maybe we want to make it warning to get full benefit, we might need lots of suppress though

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Talked with @bartonjs we will make it warning after fixing/suppressing all warnings. For now, I will leave this PR on hold until applying his suggestions on improving analyzer:

  • maybe we only want the analyzer to report for public/protected/protected ( do not warn for internal private methods).
  • We could include the generic method parameters (and possibly the generic type parameters for constructors) as legal targets.

Then we might have much less warning need to fix/suppress, and i might update this PR with all repo fix (coreclr+libs+mono)

<Rule Id="CA2211" Action="None" /> <!-- Non-constant fields should not be visible -->
<Rule Id="CA2213" Action="None" /> <!-- Disposable fields should be disposed -->
<Rule Id="CA2214" Action="None" /> <!-- Do not call overridable methods in constructors -->
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -124,7 +124,7 @@ public static object GetClassFactoryForType(ComActivationContext cxt)

if (!Path.IsPathRooted(cxt.AssemblyPath))
{
throw new ArgumentException();
throw new ArgumentException(null, nameof(cxt));
Comment thread
AaronRobinsonMSFT marked this conversation as resolved.
}

Type classType = FindClassType(cxt.ClassId, cxt.AssemblyPath, cxt.AssemblyName, cxt.TypeName);
Expand DownExpand Up@@ -156,7 +156,7 @@ public static void ClassRegistrationScenarioForType(ComActivationContext cxt, bo

if (!Path.IsPathRooted(cxt.AssemblyPath))
{
throw new ArgumentException();
throw new ArgumentException(null, nameof(cxt));
}

Type classType = FindClassType(cxt.ClassId, cxt.AssemblyPath, cxt.AssemblyName, cxt.TypeName);
Expand DownExpand Up@@ -288,7 +288,7 @@ public static unsafe int RegisterClassForTypeInternal(ComActivationContextIntern
if (cxtInt.InterfaceId != Guid.Empty
|| cxtInt.ClassFactoryDest != IntPtr.Zero)
{
throw new ArgumentException();
throw new ArgumentException(null, nameof(pCxtInt));
}

try
Expand DownExpand Up@@ -328,7 +328,7 @@ public static unsafe int UnregisterClassForTypeInternal(ComActivationContextInte
if (cxtInt.InterfaceId != Guid.Empty
|| cxtInt.ClassFactoryDest != IntPtr.Zero)
{
throw new ArgumentException();
throw new ArgumentException(null, nameof(pCxtInt));
}

try
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/src/System.Private.CoreLib/src/System/GC.cs
Original file line numberDiff line numberDiff line change
Expand Up@@ -135,7 +135,7 @@ public static void AddMemoryPressure(long bytesAllocated)

if ((4 == IntPtr.Size) && (bytesAllocated > int.MaxValue))
{
throw new ArgumentOutOfRangeException("pressure",
throw new ArgumentOutOfRangeException(nameof(bytesAllocated),
SR.ArgumentOutOfRange_MustBeNonNegInt32);
}

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -121,7 +121,7 @@ public IntPtr GetOrCreateComInterfaceForObject(object instance, CreateComInterfa
{
IntPtr ptr;
if (!TryGetOrCreateComInterfaceForObjectInternal(this, instance, flags, out ptr))
throw new ArgumentException();
throw new ArgumentException(null, nameof(instance));

return ptr;
}
Expand DownExpand Up@@ -187,7 +187,7 @@ public object GetOrCreateObjectForComInstance(IntPtr externalComObject, CreateOb
{
object? obj;
if (!TryGetOrCreateObjectForComInstanceInternal(this, externalComObject, flags, null, out obj))
throw new ArgumentNullException();
throw new ArgumentNullException(nameof(externalComObject));

return obj!;
}
Expand DownExpand Up@@ -230,7 +230,7 @@ public object GetOrRegisterObjectForComInstance(IntPtr externalComObject, Create

object? obj;
if (!TryGetOrCreateObjectForComInstanceInternal(this, externalComObject, flags, wrapper, out obj))
throw new ArgumentNullException();
throw new ArgumentNullException(nameof(externalComObject));

return obj!;
}
Expand DownExpand Up@@ -319,4 +319,4 @@ internal static int CallICustomQueryInterface(object customQueryInterfaceMaybe,
return (int)customQueryInterface.GetInterface(ref iid, out ppObject);
}
}
}
}
Original file line numberDiff line numberDiff line change
Expand Up@@ -1896,7 +1896,7 @@ private static void ThrowIfTypeNeverValidGenericArgument(RuntimeType type)
internal static void SanityCheckGenericArguments(RuntimeType[] genericArguments, RuntimeType[] genericParamters)
{
if (genericArguments == null)
throw new ArgumentNullException();
throw new ArgumentNullException(nameof(genericArguments));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

genericArguments was never supplied by the user. As such, maybe this code ought to not throw at all (just let it throw NRE). But, not suggesting you change it.


for (int i = 0; i < genericArguments.Length; i++)
{
Expand DownExpand Up@@ -2752,7 +2752,7 @@ public override InterfaceMapping GetInterfaceMap(Type ifaceType)
protected override PropertyInfo? GetPropertyImpl(
string name, BindingFlags bindingAttr, Binder? binder, Type? returnType, Type[]? types, ParameterModifier[]? modifiers)
{
if (name == null) throw new ArgumentNullException();
if (name == null) throw new ArgumentNullException(nameof(name));

ListBuilder<PropertyInfo> candidates = GetPropertyCandidates(name, bindingAttr, types, false);

Expand DownExpand Up@@ -2788,7 +2788,7 @@ public override InterfaceMapping GetInterfaceMap(Type ifaceType)

public override EventInfo? GetEvent(string name, BindingFlags bindingAttr)
{
if (name is null) throw new ArgumentNullException();
if (name is null) throw new ArgumentNullException(nameof(name));

FilterHelper(bindingAttr, ref name, out _, out MemberListType listType);

Expand All@@ -2814,7 +2814,7 @@ public override InterfaceMapping GetInterfaceMap(Type ifaceType)

public override FieldInfo? GetField(string name, BindingFlags bindingAttr)
{
if (name is null) throw new ArgumentNullException();
if (name is null) throw new ArgumentNullException(nameof(name));

FilterHelper(bindingAttr, ref name, out _, out MemberListType listType);

Expand DownExpand Up@@ -2851,7 +2851,7 @@ public override InterfaceMapping GetInterfaceMap(Type ifaceType)

public override Type? GetInterface(string fullname, bool ignoreCase)
{
if (fullname is null) throw new ArgumentNullException();
if (fullname is null) throw new ArgumentNullException(nameof(fullname));

BindingFlags bindingAttr = BindingFlags.Public | BindingFlags.NonPublic;

Expand DownExpand Up@@ -2885,7 +2885,7 @@ public override InterfaceMapping GetInterfaceMap(Type ifaceType)

public override Type? GetNestedType(string fullname, BindingFlags bindingAttr)
{
if (fullname is null) throw new ArgumentNullException();
if (fullname is null) throw new ArgumentNullException(nameof(fullname));

bindingAttr &= ~BindingFlags.Static;
string name, ns;
Expand DownExpand Up@@ -2913,7 +2913,7 @@ public override InterfaceMapping GetInterfaceMap(Type ifaceType)

public override MemberInfo[] GetMember(string name, MemberTypes type, BindingFlags bindingAttr)
{
if (name is null) throw new ArgumentNullException();
if (name is null) throw new ArgumentNullException(nameof(name));

ListBuilder<MethodInfo> methods = default;
ListBuilder<ConstructorInfo> constructors = default;
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -287,7 +287,7 @@ bool compressStack
}
else
{
Comment thread
buyaa-n marked this conversation as resolved.
throw new ArgumentNullException(nameof(WaitOrTimerCallback));
throw new ArgumentNullException(nameof(callBack));
}
return registeredWaitHandle;
}
Expand Down
4 changes: 2 additions & 2 deletions src/libraries/Common/src/System/Threading/Tasks/TaskToApm.cs
Original file line numberDiff line numberDiff line change
Expand Up@@ -43,7 +43,7 @@ public static void End(IAsyncResult asyncResult)
return;
}

throw new ArgumentNullException();
throw new ArgumentNullException(nameof(asyncResult));
}

/// <summary>Processes an IAsyncResult returned by Begin.</summary>
Expand All@@ -55,7 +55,7 @@ public static TResult End<TResult>(IAsyncResult asyncResult)
return task.GetAwaiter().GetResult();
}

throw new ArgumentNullException();
throw new ArgumentNullException(nameof(asyncResult));
}

/// <summary>Provides a simple IAsyncResult that wraps a Task.</summary>
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -32,12 +32,12 @@ internal DiagnosticCounter(string name, EventSource eventSource)
{
if (name == null)
{
throw new ArgumentNullException(nameof(Name));
throw new ArgumentNullException(nameof(name));
}

if (eventSource == null)
{
throw new ArgumentNullException(nameof(EventSource));
throw new ArgumentNullException(nameof(eventSource));
}

Name = name;
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -262,7 +262,7 @@ private void Write<T>(EventSource eventSource, string? eventName, ref EventSourc
if (this.state != State.Started)
throw new InvalidOperationException(); // Write after stop.
if (eventName == null)
throw new ArgumentNullException();
throw new ArgumentNullException(nameof(eventName));

eventSource.Write(eventName, ref options, ref this.activityId, ref s_empty, ref data);
}
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -813,7 +813,7 @@ private static int AddValueToMetaData(List<byte> metaData, string value)
{
if (!(i + 1 < value.Length))
{
throw new ArgumentException(SR.EventSource_EvenHexDigits, "traits");
throw new ArgumentException(SR.EventSource_EvenHexDigits, nameof(value));
}
metaData.Add((byte)(HexDigit(value[i]) * 16 + HexDigit(value[i + 1])));
i++;
Expand All@@ -826,7 +826,7 @@ private static int AddValueToMetaData(List<byte> metaData, string value)
}
else
{
throw new ArgumentException(SR.Format(SR.EventSource_IllegalValue, value), "traits");
throw new ArgumentException(SR.Format(SR.EventSource_IllegalValue, value), nameof(value));
}

return metaData.Count - startPos;
Expand All@@ -850,7 +850,7 @@ private static int HexDigit(char c)
return c - 'A' + 10;
}

throw new ArgumentException(SR.Format(SR.EventSource_BadHexDigit, c), "traits");
throw new ArgumentException(SR.Format(SR.EventSource_BadHexDigit, c), nameof(c));
}

private NameInfo? UpdateDescriptor(
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -394,7 +394,7 @@ public virtual unsafe void Write(string value)
{
if (charStart < 0 || charCount < 0 || charStart > value.Length - charCount)
{
throw new ArgumentOutOfRangeException(nameof(charCount));
throw new ArgumentOutOfRangeException(nameof(value));
}
fixed (char* pChars = value)
{
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -415,7 +415,7 @@ public unsafe byte* PositionPointer
throw new IOException(SR.IO_SeekBeforeBegin);
long newPosition = (long)value - (long)_mem;
if (newPosition < 0)
throw new ArgumentOutOfRangeException("offset", SR.ArgumentOutOfRange_UnmanagedMemStreamLength);
throw new ArgumentOutOfRangeException(nameof(value), SR.ArgumentOutOfRange_UnmanagedMemStreamLength);

Interlocked.Exchange(ref _position, newPosition);
}
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -63,7 +63,7 @@ public static string ComputeDisplayName(string? name, Version? version, string?
if (pkt != null)
{
if (pkt.Length > PUBLIC_KEY_TOKEN_LEN)
throw new ArgumentException();
throw new ArgumentException(null, nameof(pkt));

sb.Append(", PublicKeyToken=");
if (pkt.Length == 0)
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -97,7 +97,7 @@ internal static unsafe int GetAnsiStringByteCount(ReadOnlySpan<char> chars)
byteLength = Interop.Kernel32.WideCharToMultiByte(
Interop.Kernel32.CP_ACP, Interop.Kernel32.WC_NO_BEST_FIT_CHARS, pChars, chars.Length, null, 0, IntPtr.Zero, IntPtr.Zero);
if (byteLength <= 0)
throw new ArgumentException();
throw new ArgumentException(null, nameof(chars));
}
}

Expand All@@ -121,7 +121,7 @@ internal static unsafe void GetAnsiStringBytes(ReadOnlySpan<char> chars, Span<by
byteLength = Interop.Kernel32.WideCharToMultiByte(
Interop.Kernel32.CP_ACP, Interop.Kernel32.WC_NO_BEST_FIT_CHARS, pChars, chars.Length, pBytes, bytes.Length, IntPtr.Zero, IntPtr.Zero);
if (byteLength <= 0)
throw new ArgumentException();
throw new ArgumentException(null, nameof(bytes));
}
}

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -109,7 +109,7 @@ internal EncoderFallbackException(
}
if (!char.IsLowSurrogate(charUnknownLow))
{
throw new ArgumentOutOfRangeException(nameof(CharUnknownLow),
throw new ArgumentOutOfRangeException(nameof(charUnknownLow),
SR.Format(SR.ArgumentOutOfRange_Range, 0xDC00, 0xDFFF));
}

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -961,7 +961,7 @@ private StringBuilder AppendCore(StringBuilder value, int startIndex, int count)

if ((uint)newLength > (uint)m_MaxCapacity)
{
throw new ArgumentOutOfRangeException(nameof(Capacity), SR.ArgumentOutOfRange_Capacity);
throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_Capacity);
}

while (count > 0)
Expand DownExpand Up@@ -1144,7 +1144,9 @@ public StringBuilder Remove(int startIndex, int length)
return this;
}

#pragma warning disable CA1830 // Prefer strongly-typed Append and Insert method overloads on StringBuilder.
public StringBuilder Append(bool value) => Append(value.ToString());
#pragma warning restore CA1830 // Prefer strongly-typed Append and Insert method overloads on StringBuilder.

public StringBuilder Append(char value)
{
Expand DownExpand Up@@ -2401,7 +2403,7 @@ private void ExpandByABlock(int minBlockCharCount)

if ((minBlockCharCount + Length) > m_MaxCapacity || minBlockCharCount + Length < minBlockCharCount)
{
throw new ArgumentOutOfRangeException("requiredLength", SR.ArgumentOutOfRange_SmallCapacity);
throw new ArgumentOutOfRangeException(nameof(minBlockCharCount), SR.ArgumentOutOfRange_SmallCapacity);
}

// - We always need to make the new chunk at least as big as was requested (`minBlockCharCount`).
Expand DownExpand Up@@ -2490,7 +2492,7 @@ private void MakeRoom(int index, int count, out StringBuilder chunk, out int ind

if (count + Length > m_MaxCapacity || count + Length < count)
{
throw new ArgumentOutOfRangeException("requiredLength", SR.ArgumentOutOfRange_SmallCapacity);
throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_SmallCapacity);
}

chunk = this;
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -243,7 +243,7 @@ public bool TrySetApartmentState(ApartmentState state)
break;

default:
throw new ArgumentOutOfRangeException(SR.ArgumentOutOfRange_Enum, nameof(state));
throw new ArgumentOutOfRangeException(nameof(state), SR.ArgumentOutOfRange_Enum);
}

return TrySetApartmentStateUnchecked(state);
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -165,7 +165,7 @@ public void GetRuntimeEvent()
});


Assert.Throws<ArgumentNullException>(null, () =>
Assert.Throws<ArgumentNullException>("name", () =>
{
typeof(RuntimeReflectionExtensionsTests).GetRuntimeEvent(null);
});
Expand DownExpand Up@@ -250,7 +250,7 @@ public void GetRuntimeField()
});


Assert.Throws<ArgumentNullException>(null, () =>
Assert.Throws<ArgumentNullException>("name", () =>
{
typeof(RuntimeReflectionExtensionsTests).GetRuntimeField(null);
});
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -40,7 +40,7 @@ public void Ctor_NullType_ThrowsNullReferenceException()
[Fact]
public void Ctor_NullEventName_ThrowsArgumentNullException()
{
AssertExtensions.Throws<ArgumentNullException>(null, () => new ComAwareEventInfo(typeof(NonComObject), null));
AssertExtensions.Throws<ArgumentNullException>("name", () => new ComAwareEventInfo(typeof(NonComObject), null));
}

[Fact]
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -186,8 +186,8 @@ public void OffsetOf_NullType_ThrowsArgumentNullException()
[Fact]
public void OffsetOf_NullFieldName_ThrowsArgumentNullException()
{
AssertExtensions.Throws<ArgumentNullException>(null, () => Marshal.OffsetOf(new object().GetType(), null));
AssertExtensions.Throws<ArgumentNullException>(null, () => Marshal.OffsetOf<object>(null));
AssertExtensions.Throws<ArgumentNullException>("name", () => Marshal.OffsetOf(new object().GetType(), null));
AssertExtensions.Throws<ArgumentNullException>("name", () => Marshal.OffsetOf<object>(null));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If Marshal.OffsetOf were a more entry-level method, I'd advocate taking a change for it to validate the field name directly so it could throw the ANE with the correct parameter name ("fieldName"). But I'm guessing our position right now is "it's an advanced enough API that the caller is expected to realize the parameter sharing between OffsetOf's fieldName and GetField's name."

Writing this down in case someone else is iffy about it and wants to have the discussion. But currently sighing and not recommending further action.

}

[Fact]
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content
Closed
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
2 changes: 1 addition & 1 deletion eng/CodeAnalysis.ruleset
Original file line numberDiff line numberDiff line change
Expand Up@@ -106,7 +106,7 @@
<Rule Id="CA2200" Action="Warning" /> <!-- Rethrow to preserve stack details. -->
<Rule Id="CA2201" Action="None" /> <!-- Do not raise reserved exception types -->
<Rule Id="CA2207" Action="Warning" /> <!-- Initialize value type static fields inline -->
<Rule Id="CA2208" Action="None" /> <!-- Instantiate argument exceptions correctly -->
<Rule Id="CA2208" Action="Info" /> <!-- Instantiate argument exceptions correctly -->

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would have thought we wanted Warnings here (with everything fixed or suppressed by this PR)

@buyaa-nbuyaa-nApr 20, 2020

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have discussed to upgrade severity level from hidden to info, so I thought I should make it same here, but yes maybe we want to make it warning to get full benefit, we might need lots of suppress though

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Talked with @bartonjs we will make it warning after fixing/suppressing all warnings. For now, I will leave this PR on hold until applying his suggestions on improving analyzer:

  • maybe we only want the analyzer to report for public/protected/protected ( do not warn for internal private methods).
  • We could include the generic method parameters (and possibly the generic type parameters for constructors) as legal targets.

Then we might have much less warning need to fix/suppress, and i might update this PR with all repo fix (coreclr+libs+mono)

<Rule Id="CA2211" Action="None" /> <!-- Non-constant fields should not be visible -->
<Rule Id="CA2213" Action="None" /> <!-- Disposable fields should be disposed -->
<Rule Id="CA2214" Action="None" /> <!-- Do not call overridable methods in constructors -->
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -124,7 +124,7 @@ public static object GetClassFactoryForType(ComActivationContext cxt)

if (!Path.IsPathRooted(cxt.AssemblyPath))
{
throw new ArgumentException();
throw new ArgumentException(null, nameof(cxt));
Comment thread
AaronRobinsonMSFT marked this conversation as resolved.
}

Type classType = FindClassType(cxt.ClassId, cxt.AssemblyPath, cxt.AssemblyName, cxt.TypeName);
Expand DownExpand Up@@ -156,7 +156,7 @@ public static void ClassRegistrationScenarioForType(ComActivationContext cxt, bo

if (!Path.IsPathRooted(cxt.AssemblyPath))
{
throw new ArgumentException();
throw new ArgumentException(null, nameof(cxt));
}

Type classType = FindClassType(cxt.ClassId, cxt.AssemblyPath, cxt.AssemblyName, cxt.TypeName);
Expand DownExpand Up@@ -288,7 +288,7 @@ public static unsafe int RegisterClassForTypeInternal(ComActivationContextIntern
if (cxtInt.InterfaceId != Guid.Empty
|| cxtInt.ClassFactoryDest != IntPtr.Zero)
{
throw new ArgumentException();
throw new ArgumentException(null, nameof(pCxtInt));
}

try
Expand DownExpand Up@@ -328,7 +328,7 @@ public static unsafe int UnregisterClassForTypeInternal(ComActivationContextInte
if (cxtInt.InterfaceId != Guid.Empty
|| cxtInt.ClassFactoryDest != IntPtr.Zero)
{
throw new ArgumentException();
throw new ArgumentException(null, nameof(pCxtInt));
}

try
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/src/System.Private.CoreLib/src/System/GC.cs
Original file line numberDiff line numberDiff line change
Expand Up@@ -135,7 +135,7 @@ public static void AddMemoryPressure(long bytesAllocated)

if ((4 == IntPtr.Size) && (bytesAllocated > int.MaxValue))
{
throw new ArgumentOutOfRangeException("pressure",
throw new ArgumentOutOfRangeException(nameof(bytesAllocated),
SR.ArgumentOutOfRange_MustBeNonNegInt32);
}

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -121,7 +121,7 @@ public IntPtr GetOrCreateComInterfaceForObject(object instance, CreateComInterfa
{
IntPtr ptr;
if (!TryGetOrCreateComInterfaceForObjectInternal(this, instance, flags, out ptr))
throw new ArgumentException();
throw new ArgumentException(null, nameof(instance));

return ptr;
}
Expand DownExpand Up@@ -187,7 +187,7 @@ public object GetOrCreateObjectForComInstance(IntPtr externalComObject, CreateOb
{
object? obj;
if (!TryGetOrCreateObjectForComInstanceInternal(this, externalComObject, flags, null, out obj))
throw new ArgumentNullException();
throw new ArgumentNullException(nameof(externalComObject));

return obj!;
}
Expand DownExpand Up@@ -230,7 +230,7 @@ public object GetOrRegisterObjectForComInstance(IntPtr externalComObject, Create

object? obj;
if (!TryGetOrCreateObjectForComInstanceInternal(this, externalComObject, flags, wrapper, out obj))
throw new ArgumentNullException();
throw new ArgumentNullException(nameof(externalComObject));

return obj!;
}
Expand DownExpand Up@@ -319,4 +319,4 @@ internal static int CallICustomQueryInterface(object customQueryInterfaceMaybe,
return (int)customQueryInterface.GetInterface(ref iid, out ppObject);
}
}
}
}
Original file line numberDiff line numberDiff line change
Expand Up@@ -1896,7 +1896,7 @@ private static void ThrowIfTypeNeverValidGenericArgument(RuntimeType type)
internal static void SanityCheckGenericArguments(RuntimeType[] genericArguments, RuntimeType[] genericParamters)
{
if (genericArguments == null)
throw new ArgumentNullException();
throw new ArgumentNullException(nameof(genericArguments));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

genericArguments was never supplied by the user. As such, maybe this code ought to not throw at all (just let it throw NRE). But, not suggesting you change it.


for (int i = 0; i < genericArguments.Length; i++)
{
Expand DownExpand Up@@ -2752,7 +2752,7 @@ public override InterfaceMapping GetInterfaceMap(Type ifaceType)
protected override PropertyInfo? GetPropertyImpl(
string name, BindingFlags bindingAttr, Binder? binder, Type? returnType, Type[]? types, ParameterModifier[]? modifiers)
{
if (name == null) throw new ArgumentNullException();
if (name == null) throw new ArgumentNullException(nameof(name));

ListBuilder<PropertyInfo> candidates = GetPropertyCandidates(name, bindingAttr, types, false);

Expand DownExpand Up@@ -2788,7 +2788,7 @@ public override InterfaceMapping GetInterfaceMap(Type ifaceType)

public override EventInfo? GetEvent(string name, BindingFlags bindingAttr)
{
if (name is null) throw new ArgumentNullException();
if (name is null) throw new ArgumentNullException(nameof(name));

FilterHelper(bindingAttr, ref name, out _, out MemberListType listType);

Expand All@@ -2814,7 +2814,7 @@ public override InterfaceMapping GetInterfaceMap(Type ifaceType)

public override FieldInfo? GetField(string name, BindingFlags bindingAttr)
{
if (name is null) throw new ArgumentNullException();
if (name is null) throw new ArgumentNullException(nameof(name));

FilterHelper(bindingAttr, ref name, out _, out MemberListType listType);

Expand DownExpand Up@@ -2851,7 +2851,7 @@ public override InterfaceMapping GetInterfaceMap(Type ifaceType)

public override Type? GetInterface(string fullname, bool ignoreCase)
{
if (fullname is null) throw new ArgumentNullException();
if (fullname is null) throw new ArgumentNullException(nameof(fullname));

BindingFlags bindingAttr = BindingFlags.Public | BindingFlags.NonPublic;

Expand DownExpand Up@@ -2885,7 +2885,7 @@ public override InterfaceMapping GetInterfaceMap(Type ifaceType)

public override Type? GetNestedType(string fullname, BindingFlags bindingAttr)
{
if (fullname is null) throw new ArgumentNullException();
if (fullname is null) throw new ArgumentNullException(nameof(fullname));

bindingAttr &= ~BindingFlags.Static;
string name, ns;
Expand DownExpand Up@@ -2913,7 +2913,7 @@ public override InterfaceMapping GetInterfaceMap(Type ifaceType)

public override MemberInfo[] GetMember(string name, MemberTypes type, BindingFlags bindingAttr)
{
if (name is null) throw new ArgumentNullException();
if (name is null) throw new ArgumentNullException(nameof(name));

ListBuilder<MethodInfo> methods = default;
ListBuilder<ConstructorInfo> constructors = default;
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -287,7 +287,7 @@ bool compressStack
}
else
{
Comment thread
buyaa-n marked this conversation as resolved.
throw new ArgumentNullException(nameof(WaitOrTimerCallback));
throw new ArgumentNullException(nameof(callBack));
}
return registeredWaitHandle;
}
Expand Down
4 changes: 2 additions & 2 deletions src/libraries/Common/src/System/Threading/Tasks/TaskToApm.cs
Original file line numberDiff line numberDiff line change
Expand Up@@ -43,7 +43,7 @@ public static void End(IAsyncResult asyncResult)
return;
}

throw new ArgumentNullException();
throw new ArgumentNullException(nameof(asyncResult));
}

/// <summary>Processes an IAsyncResult returned by Begin.</summary>
Expand All@@ -55,7 +55,7 @@ public static TResult End<TResult>(IAsyncResult asyncResult)
return task.GetAwaiter().GetResult();
}

throw new ArgumentNullException();
throw new ArgumentNullException(nameof(asyncResult));
}

/// <summary>Provides a simple IAsyncResult that wraps a Task.</summary>
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -32,12 +32,12 @@ internal DiagnosticCounter(string name, EventSource eventSource)
{
if (name == null)
{
throw new ArgumentNullException(nameof(Name));
throw new ArgumentNullException(nameof(name));
}

if (eventSource == null)
{
throw new ArgumentNullException(nameof(EventSource));
throw new ArgumentNullException(nameof(eventSource));
}

Name = name;
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -262,7 +262,7 @@ private void Write<T>(EventSource eventSource, string? eventName, ref EventSourc
if (this.state != State.Started)
throw new InvalidOperationException(); // Write after stop.
if (eventName == null)
throw new ArgumentNullException();
throw new ArgumentNullException(nameof(eventName));

eventSource.Write(eventName, ref options, ref this.activityId, ref s_empty, ref data);
}
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -813,7 +813,7 @@ private static int AddValueToMetaData(List<byte> metaData, string value)
{
if (!(i + 1 < value.Length))
{
throw new ArgumentException(SR.EventSource_EvenHexDigits, "traits");
throw new ArgumentException(SR.EventSource_EvenHexDigits, nameof(value));
}
metaData.Add((byte)(HexDigit(value[i]) * 16 + HexDigit(value[i + 1])));
i++;
Expand All@@ -826,7 +826,7 @@ private static int AddValueToMetaData(List<byte> metaData, string value)
}
else
{
throw new ArgumentException(SR.Format(SR.EventSource_IllegalValue, value), "traits");
throw new ArgumentException(SR.Format(SR.EventSource_IllegalValue, value), nameof(value));
}

return metaData.Count - startPos;
Expand All@@ -850,7 +850,7 @@ private static int HexDigit(char c)
return c - 'A' + 10;
}

throw new ArgumentException(SR.Format(SR.EventSource_BadHexDigit, c), "traits");
throw new ArgumentException(SR.Format(SR.EventSource_BadHexDigit, c), nameof(c));
}

private NameInfo? UpdateDescriptor(
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -394,7 +394,7 @@ public virtual unsafe void Write(string value)
{
if (charStart < 0 || charCount < 0 || charStart > value.Length - charCount)
{
throw new ArgumentOutOfRangeException(nameof(charCount));
throw new ArgumentOutOfRangeException(nameof(value));
}
fixed (char* pChars = value)
{
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -415,7 +415,7 @@ public unsafe byte* PositionPointer
throw new IOException(SR.IO_SeekBeforeBegin);
long newPosition = (long)value - (long)_mem;
if (newPosition < 0)
throw new ArgumentOutOfRangeException("offset", SR.ArgumentOutOfRange_UnmanagedMemStreamLength);
throw new ArgumentOutOfRangeException(nameof(value), SR.ArgumentOutOfRange_UnmanagedMemStreamLength);

Interlocked.Exchange(ref _position, newPosition);
}
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -63,7 +63,7 @@ public static string ComputeDisplayName(string? name, Version? version, string?
if (pkt != null)
{
if (pkt.Length > PUBLIC_KEY_TOKEN_LEN)
throw new ArgumentException();
throw new ArgumentException(null, nameof(pkt));

sb.Append(", PublicKeyToken=");
if (pkt.Length == 0)
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -97,7 +97,7 @@ internal static unsafe int GetAnsiStringByteCount(ReadOnlySpan<char> chars)
byteLength = Interop.Kernel32.WideCharToMultiByte(
Interop.Kernel32.CP_ACP, Interop.Kernel32.WC_NO_BEST_FIT_CHARS, pChars, chars.Length, null, 0, IntPtr.Zero, IntPtr.Zero);
if (byteLength <= 0)
throw new ArgumentException();
throw new ArgumentException(null, nameof(chars));
}
}

Expand All@@ -121,7 +121,7 @@ internal static unsafe void GetAnsiStringBytes(ReadOnlySpan<char> chars, Span<by
byteLength = Interop.Kernel32.WideCharToMultiByte(
Interop.Kernel32.CP_ACP, Interop.Kernel32.WC_NO_BEST_FIT_CHARS, pChars, chars.Length, pBytes, bytes.Length, IntPtr.Zero, IntPtr.Zero);
if (byteLength <= 0)
throw new ArgumentException();
throw new ArgumentException(null, nameof(bytes));
}
}

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -109,7 +109,7 @@ internal EncoderFallbackException(
}
if (!char.IsLowSurrogate(charUnknownLow))
{
throw new ArgumentOutOfRangeException(nameof(CharUnknownLow),
throw new ArgumentOutOfRangeException(nameof(charUnknownLow),
SR.Format(SR.ArgumentOutOfRange_Range, 0xDC00, 0xDFFF));
}

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -961,7 +961,7 @@ private StringBuilder AppendCore(StringBuilder value, int startIndex, int count)

if ((uint)newLength > (uint)m_MaxCapacity)
{
throw new ArgumentOutOfRangeException(nameof(Capacity), SR.ArgumentOutOfRange_Capacity);
throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_Capacity);
}

while (count > 0)
Expand DownExpand Up@@ -1144,7 +1144,9 @@ public StringBuilder Remove(int startIndex, int length)
return this;
}

#pragma warning disable CA1830 // Prefer strongly-typed Append and Insert method overloads on StringBuilder.
public StringBuilder Append(bool value) => Append(value.ToString());
#pragma warning restore CA1830 // Prefer strongly-typed Append and Insert method overloads on StringBuilder.

public StringBuilder Append(char value)
{
Expand DownExpand Up@@ -2401,7 +2403,7 @@ private void ExpandByABlock(int minBlockCharCount)

if ((minBlockCharCount + Length) > m_MaxCapacity || minBlockCharCount + Length < minBlockCharCount)
{
throw new ArgumentOutOfRangeException("requiredLength", SR.ArgumentOutOfRange_SmallCapacity);
throw new ArgumentOutOfRangeException(nameof(minBlockCharCount), SR.ArgumentOutOfRange_SmallCapacity);
}

// - We always need to make the new chunk at least as big as was requested (`minBlockCharCount`).
Expand DownExpand Up@@ -2490,7 +2492,7 @@ private void MakeRoom(int index, int count, out StringBuilder chunk, out int ind

if (count + Length > m_MaxCapacity || count + Length < count)
{
throw new ArgumentOutOfRangeException("requiredLength", SR.ArgumentOutOfRange_SmallCapacity);
throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_SmallCapacity);
}

chunk = this;
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -243,7 +243,7 @@ public bool TrySetApartmentState(ApartmentState state)
break;

default:
throw new ArgumentOutOfRangeException(SR.ArgumentOutOfRange_Enum, nameof(state));
throw new ArgumentOutOfRangeException(nameof(state), SR.ArgumentOutOfRange_Enum);
}

return TrySetApartmentStateUnchecked(state);
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -165,7 +165,7 @@ public void GetRuntimeEvent()
});


Assert.Throws<ArgumentNullException>(null, () =>
Assert.Throws<ArgumentNullException>("name", () =>
{
typeof(RuntimeReflectionExtensionsTests).GetRuntimeEvent(null);
});
Expand DownExpand Up@@ -250,7 +250,7 @@ public void GetRuntimeField()
});


Assert.Throws<ArgumentNullException>(null, () =>
Assert.Throws<ArgumentNullException>("name", () =>
{
typeof(RuntimeReflectionExtensionsTests).GetRuntimeField(null);
});
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -40,7 +40,7 @@ public void Ctor_NullType_ThrowsNullReferenceException()
[Fact]
public void Ctor_NullEventName_ThrowsArgumentNullException()
{
AssertExtensions.Throws<ArgumentNullException>(null, () => new ComAwareEventInfo(typeof(NonComObject), null));
AssertExtensions.Throws<ArgumentNullException>("name", () => new ComAwareEventInfo(typeof(NonComObject), null));
}

[Fact]
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -186,8 +186,8 @@ public void OffsetOf_NullType_ThrowsArgumentNullException()
[Fact]
public void OffsetOf_NullFieldName_ThrowsArgumentNullException()
{
AssertExtensions.Throws<ArgumentNullException>(null, () => Marshal.OffsetOf(new object().GetType(), null));
AssertExtensions.Throws<ArgumentNullException>(null, () => Marshal.OffsetOf<object>(null));
AssertExtensions.Throws<ArgumentNullException>("name", () => Marshal.OffsetOf(new object().GetType(), null));
AssertExtensions.Throws<ArgumentNullException>("name", () => Marshal.OffsetOf<object>(null));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If Marshal.OffsetOf were a more entry-level method, I'd advocate taking a change for it to validate the field name directly so it could throw the ANE with the correct parameter name ("fieldName"). But I'm guessing our position right now is "it's an advanced enough API that the caller is expected to realize the parameter sharing between OffsetOf's fieldName and GetField's name."

Writing this down in case someone else is iffy about it and wants to have the discussion. But currently sighing and not recommending further action.

}

[Fact]
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Closed
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
2 changes: 1 addition & 1 deletion eng/CodeAnalysis.ruleset
Original file line numberDiff line numberDiff line change
Expand Up@@ -106,7 +106,7 @@
<Rule Id="CA2200" Action="Warning" /> <!-- Rethrow to preserve stack details. -->
<Rule Id="CA2201" Action="None" /> <!-- Do not raise reserved exception types -->
<Rule Id="CA2207" Action="Warning" /> <!-- Initialize value type static fields inline -->
<Rule Id="CA2208" Action="None" /> <!-- Instantiate argument exceptions correctly -->
<Rule Id="CA2208" Action="Info" /> <!-- Instantiate argument exceptions correctly -->

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would have thought we wanted Warnings here (with everything fixed or suppressed by this PR)

@buyaa-nbuyaa-nApr 20, 2020

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have discussed to upgrade severity level from hidden to info, so I thought I should make it same here, but yes maybe we want to make it warning to get full benefit, we might need lots of suppress though

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Talked with @bartonjs we will make it warning after fixing/suppressing all warnings. For now, I will leave this PR on hold until applying his suggestions on improving analyzer:

  • maybe we only want the analyzer to report for public/protected/protected ( do not warn for internal private methods).
  • We could include the generic method parameters (and possibly the generic type parameters for constructors) as legal targets.

Then we might have much less warning need to fix/suppress, and i might update this PR with all repo fix (coreclr+libs+mono)

<Rule Id="CA2211" Action="None" /> <!-- Non-constant fields should not be visible -->
<Rule Id="CA2213" Action="None" /> <!-- Disposable fields should be disposed -->
<Rule Id="CA2214" Action="None" /> <!-- Do not call overridable methods in constructors -->
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -124,7 +124,7 @@ public static object GetClassFactoryForType(ComActivationContext cxt)

if (!Path.IsPathRooted(cxt.AssemblyPath))
{
throw new ArgumentException();
throw new ArgumentException(null, nameof(cxt));
Comment thread
AaronRobinsonMSFT marked this conversation as resolved.
}

Type classType = FindClassType(cxt.ClassId, cxt.AssemblyPath, cxt.AssemblyName, cxt.TypeName);
Expand DownExpand Up@@ -156,7 +156,7 @@ public static void ClassRegistrationScenarioForType(ComActivationContext cxt, bo

if (!Path.IsPathRooted(cxt.AssemblyPath))
{
throw new ArgumentException();
throw new ArgumentException(null, nameof(cxt));
}

Type classType = FindClassType(cxt.ClassId, cxt.AssemblyPath, cxt.AssemblyName, cxt.TypeName);
Expand DownExpand Up@@ -288,7 +288,7 @@ public static unsafe int RegisterClassForTypeInternal(ComActivationContextIntern
if (cxtInt.InterfaceId != Guid.Empty
|| cxtInt.ClassFactoryDest != IntPtr.Zero)
{
throw new ArgumentException();
throw new ArgumentException(null, nameof(pCxtInt));
}

try
Expand DownExpand Up@@ -328,7 +328,7 @@ public static unsafe int UnregisterClassForTypeInternal(ComActivationContextInte
if (cxtInt.InterfaceId != Guid.Empty
|| cxtInt.ClassFactoryDest != IntPtr.Zero)
{
throw new ArgumentException();
throw new ArgumentException(null, nameof(pCxtInt));
}

try
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/src/System.Private.CoreLib/src/System/GC.cs
Original file line numberDiff line numberDiff line change
Expand Up@@ -135,7 +135,7 @@ public static void AddMemoryPressure(long bytesAllocated)

if ((4 == IntPtr.Size) && (bytesAllocated > int.MaxValue))
{
throw new ArgumentOutOfRangeException("pressure",
throw new ArgumentOutOfRangeException(nameof(bytesAllocated),
SR.ArgumentOutOfRange_MustBeNonNegInt32);
}

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -121,7 +121,7 @@ public IntPtr GetOrCreateComInterfaceForObject(object instance, CreateComInterfa
{
IntPtr ptr;
if (!TryGetOrCreateComInterfaceForObjectInternal(this, instance, flags, out ptr))
throw new ArgumentException();
throw new ArgumentException(null, nameof(instance));

return ptr;
}
Expand DownExpand Up@@ -187,7 +187,7 @@ public object GetOrCreateObjectForComInstance(IntPtr externalComObject, CreateOb
{
object? obj;
if (!TryGetOrCreateObjectForComInstanceInternal(this, externalComObject, flags, null, out obj))
throw new ArgumentNullException();
throw new ArgumentNullException(nameof(externalComObject));

return obj!;
}
Expand DownExpand Up@@ -230,7 +230,7 @@ public object GetOrRegisterObjectForComInstance(IntPtr externalComObject, Create

object? obj;
if (!TryGetOrCreateObjectForComInstanceInternal(this, externalComObject, flags, wrapper, out obj))
throw new ArgumentNullException();
throw new ArgumentNullException(nameof(externalComObject));

return obj!;
}
Expand DownExpand Up@@ -319,4 +319,4 @@ internal static int CallICustomQueryInterface(object customQueryInterfaceMaybe,
return (int)customQueryInterface.GetInterface(ref iid, out ppObject);
}
}
}
}
Original file line numberDiff line numberDiff line change
Expand Up@@ -1896,7 +1896,7 @@ private static void ThrowIfTypeNeverValidGenericArgument(RuntimeType type)
internal static void SanityCheckGenericArguments(RuntimeType[] genericArguments, RuntimeType[] genericParamters)
{
if (genericArguments == null)
throw new ArgumentNullException();
throw new ArgumentNullException(nameof(genericArguments));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

genericArguments was never supplied by the user. As such, maybe this code ought to not throw at all (just let it throw NRE). But, not suggesting you change it.


for (int i = 0; i < genericArguments.Length; i++)
{
Expand DownExpand Up@@ -2752,7 +2752,7 @@ public override InterfaceMapping GetInterfaceMap(Type ifaceType)
protected override PropertyInfo? GetPropertyImpl(
string name, BindingFlags bindingAttr, Binder? binder, Type? returnType, Type[]? types, ParameterModifier[]? modifiers)
{
if (name == null) throw new ArgumentNullException();
if (name == null) throw new ArgumentNullException(nameof(name));

ListBuilder<PropertyInfo> candidates = GetPropertyCandidates(name, bindingAttr, types, false);

Expand DownExpand Up@@ -2788,7 +2788,7 @@ public override InterfaceMapping GetInterfaceMap(Type ifaceType)

public override EventInfo? GetEvent(string name, BindingFlags bindingAttr)
{
if (name is null) throw new ArgumentNullException();
if (name is null) throw new ArgumentNullException(nameof(name));

FilterHelper(bindingAttr, ref name, out _, out MemberListType listType);

Expand All@@ -2814,7 +2814,7 @@ public override InterfaceMapping GetInterfaceMap(Type ifaceType)

public override FieldInfo? GetField(string name, BindingFlags bindingAttr)
{
if (name is null) throw new ArgumentNullException();
if (name is null) throw new ArgumentNullException(nameof(name));

FilterHelper(bindingAttr, ref name, out _, out MemberListType listType);

Expand DownExpand Up@@ -2851,7 +2851,7 @@ public override InterfaceMapping GetInterfaceMap(Type ifaceType)

public override Type? GetInterface(string fullname, bool ignoreCase)
{
if (fullname is null) throw new ArgumentNullException();
if (fullname is null) throw new ArgumentNullException(nameof(fullname));

BindingFlags bindingAttr = BindingFlags.Public | BindingFlags.NonPublic;

Expand DownExpand Up@@ -2885,7 +2885,7 @@ public override InterfaceMapping GetInterfaceMap(Type ifaceType)

public override Type? GetNestedType(string fullname, BindingFlags bindingAttr)
{
if (fullname is null) throw new ArgumentNullException();
if (fullname is null) throw new ArgumentNullException(nameof(fullname));

bindingAttr &= ~BindingFlags.Static;
string name, ns;
Expand DownExpand Up@@ -2913,7 +2913,7 @@ public override InterfaceMapping GetInterfaceMap(Type ifaceType)

public override MemberInfo[] GetMember(string name, MemberTypes type, BindingFlags bindingAttr)
{
if (name is null) throw new ArgumentNullException();
if (name is null) throw new ArgumentNullException(nameof(name));

ListBuilder<MethodInfo> methods = default;
ListBuilder<ConstructorInfo> constructors = default;
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -287,7 +287,7 @@ bool compressStack
}
else
{
Comment thread
buyaa-n marked this conversation as resolved.
throw new ArgumentNullException(nameof(WaitOrTimerCallback));
throw new ArgumentNullException(nameof(callBack));
}
return registeredWaitHandle;
}
Expand Down
4 changes: 2 additions & 2 deletions src/libraries/Common/src/System/Threading/Tasks/TaskToApm.cs
Original file line numberDiff line numberDiff line change
Expand Up@@ -43,7 +43,7 @@ public static void End(IAsyncResult asyncResult)
return;
}

throw new ArgumentNullException();
throw new ArgumentNullException(nameof(asyncResult));
}

/// <summary>Processes an IAsyncResult returned by Begin.</summary>
Expand All@@ -55,7 +55,7 @@ public static TResult End<TResult>(IAsyncResult asyncResult)
return task.GetAwaiter().GetResult();
}

throw new ArgumentNullException();
throw new ArgumentNullException(nameof(asyncResult));
}

/// <summary>Provides a simple IAsyncResult that wraps a Task.</summary>
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -32,12 +32,12 @@ internal DiagnosticCounter(string name, EventSource eventSource)
{
if (name == null)
{
throw new ArgumentNullException(nameof(Name));
throw new ArgumentNullException(nameof(name));
}

if (eventSource == null)
{
throw new ArgumentNullException(nameof(EventSource));
throw new ArgumentNullException(nameof(eventSource));
}

Name = name;
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -262,7 +262,7 @@ private void Write<T>(EventSource eventSource, string? eventName, ref EventSourc
if (this.state != State.Started)
throw new InvalidOperationException(); // Write after stop.
if (eventName == null)
throw new ArgumentNullException();
throw new ArgumentNullException(nameof(eventName));

eventSource.Write(eventName, ref options, ref this.activityId, ref s_empty, ref data);
}
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -813,7 +813,7 @@ private static int AddValueToMetaData(List<byte> metaData, string value)
{
if (!(i + 1 < value.Length))
{
throw new ArgumentException(SR.EventSource_EvenHexDigits, "traits");
throw new ArgumentException(SR.EventSource_EvenHexDigits, nameof(value));
}
metaData.Add((byte)(HexDigit(value[i]) * 16 + HexDigit(value[i + 1])));
i++;
Expand All@@ -826,7 +826,7 @@ private static int AddValueToMetaData(List<byte> metaData, string value)
}
else
{
throw new ArgumentException(SR.Format(SR.EventSource_IllegalValue, value), "traits");
throw new ArgumentException(SR.Format(SR.EventSource_IllegalValue, value), nameof(value));
}

return metaData.Count - startPos;
Expand All@@ -850,7 +850,7 @@ private static int HexDigit(char c)
return c - 'A' + 10;
}

throw new ArgumentException(SR.Format(SR.EventSource_BadHexDigit, c), "traits");
throw new ArgumentException(SR.Format(SR.EventSource_BadHexDigit, c), nameof(c));
}

private NameInfo? UpdateDescriptor(
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -394,7 +394,7 @@ public virtual unsafe void Write(string value)
{
if (charStart < 0 || charCount < 0 || charStart > value.Length - charCount)
{
throw new ArgumentOutOfRangeException(nameof(charCount));
throw new ArgumentOutOfRangeException(nameof(value));
}
fixed (char* pChars = value)
{
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -415,7 +415,7 @@ public unsafe byte* PositionPointer
throw new IOException(SR.IO_SeekBeforeBegin);
long newPosition = (long)value - (long)_mem;
if (newPosition < 0)
throw new ArgumentOutOfRangeException("offset", SR.ArgumentOutOfRange_UnmanagedMemStreamLength);
throw new ArgumentOutOfRangeException(nameof(value), SR.ArgumentOutOfRange_UnmanagedMemStreamLength);

Interlocked.Exchange(ref _position, newPosition);
}
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -63,7 +63,7 @@ public static string ComputeDisplayName(string? name, Version? version, string?
if (pkt != null)
{
if (pkt.Length > PUBLIC_KEY_TOKEN_LEN)
throw new ArgumentException();
throw new ArgumentException(null, nameof(pkt));

sb.Append(", PublicKeyToken=");
if (pkt.Length == 0)
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -97,7 +97,7 @@ internal static unsafe int GetAnsiStringByteCount(ReadOnlySpan<char> chars)
byteLength = Interop.Kernel32.WideCharToMultiByte(
Interop.Kernel32.CP_ACP, Interop.Kernel32.WC_NO_BEST_FIT_CHARS, pChars, chars.Length, null, 0, IntPtr.Zero, IntPtr.Zero);
if (byteLength <= 0)
throw new ArgumentException();
throw new ArgumentException(null, nameof(chars));
}
}

Expand All@@ -121,7 +121,7 @@ internal static unsafe void GetAnsiStringBytes(ReadOnlySpan<char> chars, Span<by
byteLength = Interop.Kernel32.WideCharToMultiByte(
Interop.Kernel32.CP_ACP, Interop.Kernel32.WC_NO_BEST_FIT_CHARS, pChars, chars.Length, pBytes, bytes.Length, IntPtr.Zero, IntPtr.Zero);
if (byteLength <= 0)
throw new ArgumentException();
throw new ArgumentException(null, nameof(bytes));
}
}

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -109,7 +109,7 @@ internal EncoderFallbackException(
}
if (!char.IsLowSurrogate(charUnknownLow))
{
throw new ArgumentOutOfRangeException(nameof(CharUnknownLow),
throw new ArgumentOutOfRangeException(nameof(charUnknownLow),
SR.Format(SR.ArgumentOutOfRange_Range, 0xDC00, 0xDFFF));
}

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -961,7 +961,7 @@ private StringBuilder AppendCore(StringBuilder value, int startIndex, int count)

if ((uint)newLength > (uint)m_MaxCapacity)
{
throw new ArgumentOutOfRangeException(nameof(Capacity), SR.ArgumentOutOfRange_Capacity);
throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_Capacity);
}

while (count > 0)
Expand DownExpand Up@@ -1144,7 +1144,9 @@ public StringBuilder Remove(int startIndex, int length)
return this;
}

#pragma warning disable CA1830 // Prefer strongly-typed Append and Insert method overloads on StringBuilder.
public StringBuilder Append(bool value) => Append(value.ToString());
#pragma warning restore CA1830 // Prefer strongly-typed Append and Insert method overloads on StringBuilder.

public StringBuilder Append(char value)
{
Expand DownExpand Up@@ -2401,7 +2403,7 @@ private void ExpandByABlock(int minBlockCharCount)

if ((minBlockCharCount + Length) > m_MaxCapacity || minBlockCharCount + Length < minBlockCharCount)
{
throw new ArgumentOutOfRangeException("requiredLength", SR.ArgumentOutOfRange_SmallCapacity);
throw new ArgumentOutOfRangeException(nameof(minBlockCharCount), SR.ArgumentOutOfRange_SmallCapacity);
}

// - We always need to make the new chunk at least as big as was requested (`minBlockCharCount`).
Expand DownExpand Up@@ -2490,7 +2492,7 @@ private void MakeRoom(int index, int count, out StringBuilder chunk, out int ind

if (count + Length > m_MaxCapacity || count + Length < count)
{
throw new ArgumentOutOfRangeException("requiredLength", SR.ArgumentOutOfRange_SmallCapacity);
throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_SmallCapacity);
}

chunk = this;
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -243,7 +243,7 @@ public bool TrySetApartmentState(ApartmentState state)
break;

default:
throw new ArgumentOutOfRangeException(SR.ArgumentOutOfRange_Enum, nameof(state));
throw new ArgumentOutOfRangeException(nameof(state), SR.ArgumentOutOfRange_Enum);
}

return TrySetApartmentStateUnchecked(state);
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -165,7 +165,7 @@ public void GetRuntimeEvent()
});


Assert.Throws<ArgumentNullException>(null, () =>
Assert.Throws<ArgumentNullException>("name", () =>
{
typeof(RuntimeReflectionExtensionsTests).GetRuntimeEvent(null);
});
Expand DownExpand Up@@ -250,7 +250,7 @@ public void GetRuntimeField()
});


Assert.Throws<ArgumentNullException>(null, () =>
Assert.Throws<ArgumentNullException>("name", () =>
{
typeof(RuntimeReflectionExtensionsTests).GetRuntimeField(null);
});
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -40,7 +40,7 @@ public void Ctor_NullType_ThrowsNullReferenceException()
[Fact]
public void Ctor_NullEventName_ThrowsArgumentNullException()
{
AssertExtensions.Throws<ArgumentNullException>(null, () => new ComAwareEventInfo(typeof(NonComObject), null));
AssertExtensions.Throws<ArgumentNullException>("name", () => new ComAwareEventInfo(typeof(NonComObject), null));
}

[Fact]
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -186,8 +186,8 @@ public void OffsetOf_NullType_ThrowsArgumentNullException()
[Fact]
public void OffsetOf_NullFieldName_ThrowsArgumentNullException()
{
AssertExtensions.Throws<ArgumentNullException>(null, () => Marshal.OffsetOf(new object().GetType(), null));
AssertExtensions.Throws<ArgumentNullException>(null, () => Marshal.OffsetOf<object>(null));
AssertExtensions.Throws<ArgumentNullException>("name", () => Marshal.OffsetOf(new object().GetType(), null));
AssertExtensions.Throws<ArgumentNullException>("name", () => Marshal.OffsetOf<object>(null));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If Marshal.OffsetOf were a more entry-level method, I'd advocate taking a change for it to validate the field name directly so it could throw the ANE with the correct parameter name ("fieldName"). But I'm guessing our position right now is "it's an advanced enough API that the caller is expected to realize the parameter sharing between OffsetOf's fieldName and GetField's name."

Writing this down in case someone else is iffy about it and wants to have the discussion. But currently sighing and not recommending further action.

}

[Fact]
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Closed
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
2 changes: 1 addition & 1 deletion eng/CodeAnalysis.ruleset
Original file line numberDiff line numberDiff line change
Expand Up@@ -106,7 +106,7 @@
<Rule Id="CA2200" Action="Warning" /> <!-- Rethrow to preserve stack details. -->
<Rule Id="CA2201" Action="None" /> <!-- Do not raise reserved exception types -->
<Rule Id="CA2207" Action="Warning" /> <!-- Initialize value type static fields inline -->
<Rule Id="CA2208" Action="None" /> <!-- Instantiate argument exceptions correctly -->
<Rule Id="CA2208" Action="Info" /> <!-- Instantiate argument exceptions correctly -->

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would have thought we wanted Warnings here (with everything fixed or suppressed by this PR)

@buyaa-nbuyaa-nApr 20, 2020

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have discussed to upgrade severity level from hidden to info, so I thought I should make it same here, but yes maybe we want to make it warning to get full benefit, we might need lots of suppress though

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Talked with @bartonjs we will make it warning after fixing/suppressing all warnings. For now, I will leave this PR on hold until applying his suggestions on improving analyzer:

  • maybe we only want the analyzer to report for public/protected/protected ( do not warn for internal private methods).
  • We could include the generic method parameters (and possibly the generic type parameters for constructors) as legal targets.

Then we might have much less warning need to fix/suppress, and i might update this PR with all repo fix (coreclr+libs+mono)

<Rule Id="CA2211" Action="None" /> <!-- Non-constant fields should not be visible -->
<Rule Id="CA2213" Action="None" /> <!-- Disposable fields should be disposed -->
<Rule Id="CA2214" Action="None" /> <!-- Do not call overridable methods in constructors -->
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -124,7 +124,7 @@ public static object GetClassFactoryForType(ComActivationContext cxt)

if (!Path.IsPathRooted(cxt.AssemblyPath))
{
throw new ArgumentException();
throw new ArgumentException(null, nameof(cxt));
Comment thread
AaronRobinsonMSFT marked this conversation as resolved.
}

Type classType = FindClassType(cxt.ClassId, cxt.AssemblyPath, cxt.AssemblyName, cxt.TypeName);
Expand DownExpand Up@@ -156,7 +156,7 @@ public static void ClassRegistrationScenarioForType(ComActivationContext cxt, bo

if (!Path.IsPathRooted(cxt.AssemblyPath))
{
throw new ArgumentException();
throw new ArgumentException(null, nameof(cxt));
}

Type classType = FindClassType(cxt.ClassId, cxt.AssemblyPath, cxt.AssemblyName, cxt.TypeName);
Expand DownExpand Up@@ -288,7 +288,7 @@ public static unsafe int RegisterClassForTypeInternal(ComActivationContextIntern
if (cxtInt.InterfaceId != Guid.Empty
|| cxtInt.ClassFactoryDest != IntPtr.Zero)
{
throw new ArgumentException();
throw new ArgumentException(null, nameof(pCxtInt));
}

try
Expand DownExpand Up@@ -328,7 +328,7 @@ public static unsafe int UnregisterClassForTypeInternal(ComActivationContextInte
if (cxtInt.InterfaceId != Guid.Empty
|| cxtInt.ClassFactoryDest != IntPtr.Zero)
{
throw new ArgumentException();
throw new ArgumentException(null, nameof(pCxtInt));
}

try
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/src/System.Private.CoreLib/src/System/GC.cs
Original file line numberDiff line numberDiff line change
Expand Up@@ -135,7 +135,7 @@ public static void AddMemoryPressure(long bytesAllocated)

if ((4 == IntPtr.Size) && (bytesAllocated > int.MaxValue))
{
throw new ArgumentOutOfRangeException("pressure",
throw new ArgumentOutOfRangeException(nameof(bytesAllocated),
SR.ArgumentOutOfRange_MustBeNonNegInt32);
}

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -121,7 +121,7 @@ public IntPtr GetOrCreateComInterfaceForObject(object instance, CreateComInterfa
{
IntPtr ptr;
if (!TryGetOrCreateComInterfaceForObjectInternal(this, instance, flags, out ptr))
throw new ArgumentException();
throw new ArgumentException(null, nameof(instance));

return ptr;
}
Expand DownExpand Up@@ -187,7 +187,7 @@ public object GetOrCreateObjectForComInstance(IntPtr externalComObject, CreateOb
{
object? obj;
if (!TryGetOrCreateObjectForComInstanceInternal(this, externalComObject, flags, null, out obj))
throw new ArgumentNullException();
throw new ArgumentNullException(nameof(externalComObject));

return obj!;
}
Expand DownExpand Up@@ -230,7 +230,7 @@ public object GetOrRegisterObjectForComInstance(IntPtr externalComObject, Create

object? obj;
if (!TryGetOrCreateObjectForComInstanceInternal(this, externalComObject, flags, wrapper, out obj))
throw new ArgumentNullException();
throw new ArgumentNullException(nameof(externalComObject));

return obj!;
}
Expand DownExpand Up@@ -319,4 +319,4 @@ internal static int CallICustomQueryInterface(object customQueryInterfaceMaybe,
return (int)customQueryInterface.GetInterface(ref iid, out ppObject);
}
}
}
}
Original file line numberDiff line numberDiff line change
Expand Up@@ -1896,7 +1896,7 @@ private static void ThrowIfTypeNeverValidGenericArgument(RuntimeType type)
internal static void SanityCheckGenericArguments(RuntimeType[] genericArguments, RuntimeType[] genericParamters)
{
if (genericArguments == null)
throw new ArgumentNullException();
throw new ArgumentNullException(nameof(genericArguments));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

genericArguments was never supplied by the user. As such, maybe this code ought to not throw at all (just let it throw NRE). But, not suggesting you change it.


for (int i = 0; i < genericArguments.Length; i++)
{
Expand DownExpand Up@@ -2752,7 +2752,7 @@ public override InterfaceMapping GetInterfaceMap(Type ifaceType)
protected override PropertyInfo? GetPropertyImpl(
string name, BindingFlags bindingAttr, Binder? binder, Type? returnType, Type[]? types, ParameterModifier[]? modifiers)
{
if (name == null) throw new ArgumentNullException();
if (name == null) throw new ArgumentNullException(nameof(name));

ListBuilder<PropertyInfo> candidates = GetPropertyCandidates(name, bindingAttr, types, false);

Expand DownExpand Up@@ -2788,7 +2788,7 @@ public override InterfaceMapping GetInterfaceMap(Type ifaceType)

public override EventInfo? GetEvent(string name, BindingFlags bindingAttr)
{
if (name is null) throw new ArgumentNullException();
if (name is null) throw new ArgumentNullException(nameof(name));

FilterHelper(bindingAttr, ref name, out _, out MemberListType listType);

Expand All@@ -2814,7 +2814,7 @@ public override InterfaceMapping GetInterfaceMap(Type ifaceType)

public override FieldInfo? GetField(string name, BindingFlags bindingAttr)
{
if (name is null) throw new ArgumentNullException();
if (name is null) throw new ArgumentNullException(nameof(name));

FilterHelper(bindingAttr, ref name, out _, out MemberListType listType);

Expand DownExpand Up@@ -2851,7 +2851,7 @@ public override InterfaceMapping GetInterfaceMap(Type ifaceType)

public override Type? GetInterface(string fullname, bool ignoreCase)
{
if (fullname is null) throw new ArgumentNullException();
if (fullname is null) throw new ArgumentNullException(nameof(fullname));

BindingFlags bindingAttr = BindingFlags.Public | BindingFlags.NonPublic;

Expand DownExpand Up@@ -2885,7 +2885,7 @@ public override InterfaceMapping GetInterfaceMap(Type ifaceType)

public override Type? GetNestedType(string fullname, BindingFlags bindingAttr)
{
if (fullname is null) throw new ArgumentNullException();
if (fullname is null) throw new ArgumentNullException(nameof(fullname));

bindingAttr &= ~BindingFlags.Static;
string name, ns;
Expand DownExpand Up@@ -2913,7 +2913,7 @@ public override InterfaceMapping GetInterfaceMap(Type ifaceType)

public override MemberInfo[] GetMember(string name, MemberTypes type, BindingFlags bindingAttr)
{
if (name is null) throw new ArgumentNullException();
if (name is null) throw new ArgumentNullException(nameof(name));

ListBuilder<MethodInfo> methods = default;
ListBuilder<ConstructorInfo> constructors = default;
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -287,7 +287,7 @@ bool compressStack
}
else
{
Comment thread
buyaa-n marked this conversation as resolved.
throw new ArgumentNullException(nameof(WaitOrTimerCallback));
throw new ArgumentNullException(nameof(callBack));
}
return registeredWaitHandle;
}
Expand Down
4 changes: 2 additions & 2 deletions src/libraries/Common/src/System/Threading/Tasks/TaskToApm.cs
Original file line numberDiff line numberDiff line change
Expand Up@@ -43,7 +43,7 @@ public static void End(IAsyncResult asyncResult)
return;
}

throw new ArgumentNullException();
throw new ArgumentNullException(nameof(asyncResult));
}

/// <summary>Processes an IAsyncResult returned by Begin.</summary>
Expand All@@ -55,7 +55,7 @@ public static TResult End<TResult>(IAsyncResult asyncResult)
return task.GetAwaiter().GetResult();
}

throw new ArgumentNullException();
throw new ArgumentNullException(nameof(asyncResult));
}

/// <summary>Provides a simple IAsyncResult that wraps a Task.</summary>
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -32,12 +32,12 @@ internal DiagnosticCounter(string name, EventSource eventSource)
{
if (name == null)
{
throw new ArgumentNullException(nameof(Name));
throw new ArgumentNullException(nameof(name));
}

if (eventSource == null)
{
throw new ArgumentNullException(nameof(EventSource));
throw new ArgumentNullException(nameof(eventSource));
}

Name = name;
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -262,7 +262,7 @@ private void Write<T>(EventSource eventSource, string? eventName, ref EventSourc
if (this.state != State.Started)
throw new InvalidOperationException(); // Write after stop.
if (eventName == null)
throw new ArgumentNullException();
throw new ArgumentNullException(nameof(eventName));

eventSource.Write(eventName, ref options, ref this.activityId, ref s_empty, ref data);
}
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -813,7 +813,7 @@ private static int AddValueToMetaData(List<byte> metaData, string value)
{
if (!(i + 1 < value.Length))
{
throw new ArgumentException(SR.EventSource_EvenHexDigits, "traits");
throw new ArgumentException(SR.EventSource_EvenHexDigits, nameof(value));
}
metaData.Add((byte)(HexDigit(value[i]) * 16 + HexDigit(value[i + 1])));
i++;
Expand All@@ -826,7 +826,7 @@ private static int AddValueToMetaData(List<byte> metaData, string value)
}
else
{
throw new ArgumentException(SR.Format(SR.EventSource_IllegalValue, value), "traits");
throw new ArgumentException(SR.Format(SR.EventSource_IllegalValue, value), nameof(value));
}

return metaData.Count - startPos;
Expand All@@ -850,7 +850,7 @@ private static int HexDigit(char c)
return c - 'A' + 10;
}

throw new ArgumentException(SR.Format(SR.EventSource_BadHexDigit, c), "traits");
throw new ArgumentException(SR.Format(SR.EventSource_BadHexDigit, c), nameof(c));
}

private NameInfo? UpdateDescriptor(
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -394,7 +394,7 @@ public virtual unsafe void Write(string value)
{
if (charStart < 0 || charCount < 0 || charStart > value.Length - charCount)
{
throw new ArgumentOutOfRangeException(nameof(charCount));
throw new ArgumentOutOfRangeException(nameof(value));
}
fixed (char* pChars = value)
{
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -415,7 +415,7 @@ public unsafe byte* PositionPointer
throw new IOException(SR.IO_SeekBeforeBegin);
long newPosition = (long)value - (long)_mem;
if (newPosition < 0)
throw new ArgumentOutOfRangeException("offset", SR.ArgumentOutOfRange_UnmanagedMemStreamLength);
throw new ArgumentOutOfRangeException(nameof(value), SR.ArgumentOutOfRange_UnmanagedMemStreamLength);

Interlocked.Exchange(ref _position, newPosition);
}
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -63,7 +63,7 @@ public static string ComputeDisplayName(string? name, Version? version, string?
if (pkt != null)
{
if (pkt.Length > PUBLIC_KEY_TOKEN_LEN)
throw new ArgumentException();
throw new ArgumentException(null, nameof(pkt));

sb.Append(", PublicKeyToken=");
if (pkt.Length == 0)
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -97,7 +97,7 @@ internal static unsafe int GetAnsiStringByteCount(ReadOnlySpan<char> chars)
byteLength = Interop.Kernel32.WideCharToMultiByte(
Interop.Kernel32.CP_ACP, Interop.Kernel32.WC_NO_BEST_FIT_CHARS, pChars, chars.Length, null, 0, IntPtr.Zero, IntPtr.Zero);
if (byteLength <= 0)
throw new ArgumentException();
throw new ArgumentException(null, nameof(chars));
}
}

Expand All@@ -121,7 +121,7 @@ internal static unsafe void GetAnsiStringBytes(ReadOnlySpan<char> chars, Span<by
byteLength = Interop.Kernel32.WideCharToMultiByte(
Interop.Kernel32.CP_ACP, Interop.Kernel32.WC_NO_BEST_FIT_CHARS, pChars, chars.Length, pBytes, bytes.Length, IntPtr.Zero, IntPtr.Zero);
if (byteLength <= 0)
throw new ArgumentException();
throw new ArgumentException(null, nameof(bytes));
}
}

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -109,7 +109,7 @@ internal EncoderFallbackException(
}
if (!char.IsLowSurrogate(charUnknownLow))
{
throw new ArgumentOutOfRangeException(nameof(CharUnknownLow),
throw new ArgumentOutOfRangeException(nameof(charUnknownLow),
SR.Format(SR.ArgumentOutOfRange_Range, 0xDC00, 0xDFFF));
}

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -961,7 +961,7 @@ private StringBuilder AppendCore(StringBuilder value, int startIndex, int count)

if ((uint)newLength > (uint)m_MaxCapacity)
{
throw new ArgumentOutOfRangeException(nameof(Capacity), SR.ArgumentOutOfRange_Capacity);
throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_Capacity);
}

while (count > 0)
Expand DownExpand Up@@ -1144,7 +1144,9 @@ public StringBuilder Remove(int startIndex, int length)
return this;
}

#pragma warning disable CA1830 // Prefer strongly-typed Append and Insert method overloads on StringBuilder.
public StringBuilder Append(bool value) => Append(value.ToString());
#pragma warning restore CA1830 // Prefer strongly-typed Append and Insert method overloads on StringBuilder.

public StringBuilder Append(char value)
{
Expand DownExpand Up@@ -2401,7 +2403,7 @@ private void ExpandByABlock(int minBlockCharCount)

if ((minBlockCharCount + Length) > m_MaxCapacity || minBlockCharCount + Length < minBlockCharCount)
{
throw new ArgumentOutOfRangeException("requiredLength", SR.ArgumentOutOfRange_SmallCapacity);
throw new ArgumentOutOfRangeException(nameof(minBlockCharCount), SR.ArgumentOutOfRange_SmallCapacity);
}

// - We always need to make the new chunk at least as big as was requested (`minBlockCharCount`).
Expand DownExpand Up@@ -2490,7 +2492,7 @@ private void MakeRoom(int index, int count, out StringBuilder chunk, out int ind

if (count + Length > m_MaxCapacity || count + Length < count)
{
throw new ArgumentOutOfRangeException("requiredLength", SR.ArgumentOutOfRange_SmallCapacity);
throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_SmallCapacity);
}

chunk = this;
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -243,7 +243,7 @@ public bool TrySetApartmentState(ApartmentState state)
break;

default:
throw new ArgumentOutOfRangeException(SR.ArgumentOutOfRange_Enum, nameof(state));
throw new ArgumentOutOfRangeException(nameof(state), SR.ArgumentOutOfRange_Enum);
}

return TrySetApartmentStateUnchecked(state);
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -165,7 +165,7 @@ public void GetRuntimeEvent()
});


Assert.Throws<ArgumentNullException>(null, () =>
Assert.Throws<ArgumentNullException>("name", () =>
{
typeof(RuntimeReflectionExtensionsTests).GetRuntimeEvent(null);
});
Expand DownExpand Up@@ -250,7 +250,7 @@ public void GetRuntimeField()
});


Assert.Throws<ArgumentNullException>(null, () =>
Assert.Throws<ArgumentNullException>("name", () =>
{
typeof(RuntimeReflectionExtensionsTests).GetRuntimeField(null);
});
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -40,7 +40,7 @@ public void Ctor_NullType_ThrowsNullReferenceException()
[Fact]
public void Ctor_NullEventName_ThrowsArgumentNullException()
{
AssertExtensions.Throws<ArgumentNullException>(null, () => new ComAwareEventInfo(typeof(NonComObject), null));
AssertExtensions.Throws<ArgumentNullException>("name", () => new ComAwareEventInfo(typeof(NonComObject), null));
}

[Fact]
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -186,8 +186,8 @@ public void OffsetOf_NullType_ThrowsArgumentNullException()
[Fact]
public void OffsetOf_NullFieldName_ThrowsArgumentNullException()
{
AssertExtensions.Throws<ArgumentNullException>(null, () => Marshal.OffsetOf(new object().GetType(), null));
AssertExtensions.Throws<ArgumentNullException>(null, () => Marshal.OffsetOf<object>(null));
AssertExtensions.Throws<ArgumentNullException>("name", () => Marshal.OffsetOf(new object().GetType(), null));
AssertExtensions.Throws<ArgumentNullException>("name", () => Marshal.OffsetOf<object>(null));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If Marshal.OffsetOf were a more entry-level method, I'd advocate taking a change for it to validate the field name directly so it could throw the ANE with the correct parameter name ("fieldName"). But I'm guessing our position right now is "it's an advanced enough API that the caller is expected to realize the parameter sharing between OffsetOf's fieldName and GetField's name."

Writing this down in case someone else is iffy about it and wants to have the discussion. But currently sighing and not recommending further action.

}

[Fact]
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content
Closed
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
2 changes: 1 addition & 1 deletion eng/CodeAnalysis.ruleset
Original file line numberDiff line numberDiff line change
Expand Up@@ -106,7 +106,7 @@
<Rule Id="CA2200" Action="Warning" /> <!-- Rethrow to preserve stack details. -->
<Rule Id="CA2201" Action="None" /> <!-- Do not raise reserved exception types -->
<Rule Id="CA2207" Action="Warning" /> <!-- Initialize value type static fields inline -->
<Rule Id="CA2208" Action="None" /> <!-- Instantiate argument exceptions correctly -->
<Rule Id="CA2208" Action="Info" /> <!-- Instantiate argument exceptions correctly -->

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would have thought we wanted Warnings here (with everything fixed or suppressed by this PR)

@buyaa-nbuyaa-nApr 20, 2020

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have discussed to upgrade severity level from hidden to info, so I thought I should make it same here, but yes maybe we want to make it warning to get full benefit, we might need lots of suppress though

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Talked with @bartonjs we will make it warning after fixing/suppressing all warnings. For now, I will leave this PR on hold until applying his suggestions on improving analyzer:

  • maybe we only want the analyzer to report for public/protected/protected ( do not warn for internal private methods).
  • We could include the generic method parameters (and possibly the generic type parameters for constructors) as legal targets.

Then we might have much less warning need to fix/suppress, and i might update this PR with all repo fix (coreclr+libs+mono)

<Rule Id="CA2211" Action="None" /> <!-- Non-constant fields should not be visible -->
<Rule Id="CA2213" Action="None" /> <!-- Disposable fields should be disposed -->
<Rule Id="CA2214" Action="None" /> <!-- Do not call overridable methods in constructors -->
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -124,7 +124,7 @@ public static object GetClassFactoryForType(ComActivationContext cxt)

if (!Path.IsPathRooted(cxt.AssemblyPath))
{
throw new ArgumentException();
throw new ArgumentException(null, nameof(cxt));
Comment thread
AaronRobinsonMSFT marked this conversation as resolved.
}

Type classType = FindClassType(cxt.ClassId, cxt.AssemblyPath, cxt.AssemblyName, cxt.TypeName);
Expand DownExpand Up@@ -156,7 +156,7 @@ public static void ClassRegistrationScenarioForType(ComActivationContext cxt, bo

if (!Path.IsPathRooted(cxt.AssemblyPath))
{
throw new ArgumentException();
throw new ArgumentException(null, nameof(cxt));
}

Type classType = FindClassType(cxt.ClassId, cxt.AssemblyPath, cxt.AssemblyName, cxt.TypeName);
Expand DownExpand Up@@ -288,7 +288,7 @@ public static unsafe int RegisterClassForTypeInternal(ComActivationContextIntern
if (cxtInt.InterfaceId != Guid.Empty
|| cxtInt.ClassFactoryDest != IntPtr.Zero)
{
throw new ArgumentException();
throw new ArgumentException(null, nameof(pCxtInt));
}

try
Expand DownExpand Up@@ -328,7 +328,7 @@ public static unsafe int UnregisterClassForTypeInternal(ComActivationContextInte
if (cxtInt.InterfaceId != Guid.Empty
|| cxtInt.ClassFactoryDest != IntPtr.Zero)
{
throw new ArgumentException();
throw new ArgumentException(null, nameof(pCxtInt));
}

try
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/src/System.Private.CoreLib/src/System/GC.cs
Original file line numberDiff line numberDiff line change
Expand Up@@ -135,7 +135,7 @@ public static void AddMemoryPressure(long bytesAllocated)

if ((4 == IntPtr.Size) && (bytesAllocated > int.MaxValue))
{
throw new ArgumentOutOfRangeException("pressure",
throw new ArgumentOutOfRangeException(nameof(bytesAllocated),
SR.ArgumentOutOfRange_MustBeNonNegInt32);
}

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -121,7 +121,7 @@ public IntPtr GetOrCreateComInterfaceForObject(object instance, CreateComInterfa
{
IntPtr ptr;
if (!TryGetOrCreateComInterfaceForObjectInternal(this, instance, flags, out ptr))
throw new ArgumentException();
throw new ArgumentException(null, nameof(instance));

return ptr;
}
Expand DownExpand Up@@ -187,7 +187,7 @@ public object GetOrCreateObjectForComInstance(IntPtr externalComObject, CreateOb
{
object? obj;
if (!TryGetOrCreateObjectForComInstanceInternal(this, externalComObject, flags, null, out obj))
throw new ArgumentNullException();
throw new ArgumentNullException(nameof(externalComObject));

return obj!;
}
Expand DownExpand Up@@ -230,7 +230,7 @@ public object GetOrRegisterObjectForComInstance(IntPtr externalComObject, Create

object? obj;
if (!TryGetOrCreateObjectForComInstanceInternal(this, externalComObject, flags, wrapper, out obj))
throw new ArgumentNullException();
throw new ArgumentNullException(nameof(externalComObject));

return obj!;
}
Expand DownExpand Up@@ -319,4 +319,4 @@ internal static int CallICustomQueryInterface(object customQueryInterfaceMaybe,
return (int)customQueryInterface.GetInterface(ref iid, out ppObject);
}
}
}
}
Original file line numberDiff line numberDiff line change
Expand Up@@ -1896,7 +1896,7 @@ private static void ThrowIfTypeNeverValidGenericArgument(RuntimeType type)
internal static void SanityCheckGenericArguments(RuntimeType[] genericArguments, RuntimeType[] genericParamters)
{
if (genericArguments == null)
throw new ArgumentNullException();
throw new ArgumentNullException(nameof(genericArguments));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

genericArguments was never supplied by the user. As such, maybe this code ought to not throw at all (just let it throw NRE). But, not suggesting you change it.


for (int i = 0; i < genericArguments.Length; i++)
{
Expand DownExpand Up@@ -2752,7 +2752,7 @@ public override InterfaceMapping GetInterfaceMap(Type ifaceType)
protected override PropertyInfo? GetPropertyImpl(
string name, BindingFlags bindingAttr, Binder? binder, Type? returnType, Type[]? types, ParameterModifier[]? modifiers)
{
if (name == null) throw new ArgumentNullException();
if (name == null) throw new ArgumentNullException(nameof(name));

ListBuilder<PropertyInfo> candidates = GetPropertyCandidates(name, bindingAttr, types, false);

Expand DownExpand Up@@ -2788,7 +2788,7 @@ public override InterfaceMapping GetInterfaceMap(Type ifaceType)

public override EventInfo? GetEvent(string name, BindingFlags bindingAttr)
{
if (name is null) throw new ArgumentNullException();
if (name is null) throw new ArgumentNullException(nameof(name));

FilterHelper(bindingAttr, ref name, out _, out MemberListType listType);

Expand All@@ -2814,7 +2814,7 @@ public override InterfaceMapping GetInterfaceMap(Type ifaceType)

public override FieldInfo? GetField(string name, BindingFlags bindingAttr)
{
if (name is null) throw new ArgumentNullException();
if (name is null) throw new ArgumentNullException(nameof(name));

FilterHelper(bindingAttr, ref name, out _, out MemberListType listType);

Expand DownExpand Up@@ -2851,7 +2851,7 @@ public override InterfaceMapping GetInterfaceMap(Type ifaceType)

public override Type? GetInterface(string fullname, bool ignoreCase)
{
if (fullname is null) throw new ArgumentNullException();
if (fullname is null) throw new ArgumentNullException(nameof(fullname));

BindingFlags bindingAttr = BindingFlags.Public | BindingFlags.NonPublic;

Expand DownExpand Up@@ -2885,7 +2885,7 @@ public override InterfaceMapping GetInterfaceMap(Type ifaceType)

public override Type? GetNestedType(string fullname, BindingFlags bindingAttr)
{
if (fullname is null) throw new ArgumentNullException();
if (fullname is null) throw new ArgumentNullException(nameof(fullname));

bindingAttr &= ~BindingFlags.Static;
string name, ns;
Expand DownExpand Up@@ -2913,7 +2913,7 @@ public override InterfaceMapping GetInterfaceMap(Type ifaceType)

public override MemberInfo[] GetMember(string name, MemberTypes type, BindingFlags bindingAttr)
{
if (name is null) throw new ArgumentNullException();
if (name is null) throw new ArgumentNullException(nameof(name));

ListBuilder<MethodInfo> methods = default;
ListBuilder<ConstructorInfo> constructors = default;
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -287,7 +287,7 @@ bool compressStack
}
else
{
Comment thread
buyaa-n marked this conversation as resolved.
throw new ArgumentNullException(nameof(WaitOrTimerCallback));
throw new ArgumentNullException(nameof(callBack));
}
return registeredWaitHandle;
}
Expand Down
4 changes: 2 additions & 2 deletions src/libraries/Common/src/System/Threading/Tasks/TaskToApm.cs
Original file line numberDiff line numberDiff line change
Expand Up@@ -43,7 +43,7 @@ public static void End(IAsyncResult asyncResult)
return;
}

throw new ArgumentNullException();
throw new ArgumentNullException(nameof(asyncResult));
}

/// <summary>Processes an IAsyncResult returned by Begin.</summary>
Expand All@@ -55,7 +55,7 @@ public static TResult End<TResult>(IAsyncResult asyncResult)
return task.GetAwaiter().GetResult();
}

throw new ArgumentNullException();
throw new ArgumentNullException(nameof(asyncResult));
}

/// <summary>Provides a simple IAsyncResult that wraps a Task.</summary>
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -32,12 +32,12 @@ internal DiagnosticCounter(string name, EventSource eventSource)
{
if (name == null)
{
throw new ArgumentNullException(nameof(Name));
throw new ArgumentNullException(nameof(name));
}

if (eventSource == null)
{
throw new ArgumentNullException(nameof(EventSource));
throw new ArgumentNullException(nameof(eventSource));
}

Name = name;
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -262,7 +262,7 @@ private void Write<T>(EventSource eventSource, string? eventName, ref EventSourc
if (this.state != State.Started)
throw new InvalidOperationException(); // Write after stop.
if (eventName == null)
throw new ArgumentNullException();
throw new ArgumentNullException(nameof(eventName));

eventSource.Write(eventName, ref options, ref this.activityId, ref s_empty, ref data);
}
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -813,7 +813,7 @@ private static int AddValueToMetaData(List<byte> metaData, string value)
{
if (!(i + 1 < value.Length))
{
throw new ArgumentException(SR.EventSource_EvenHexDigits, "traits");
throw new ArgumentException(SR.EventSource_EvenHexDigits, nameof(value));
}
metaData.Add((byte)(HexDigit(value[i]) * 16 + HexDigit(value[i + 1])));
i++;
Expand All@@ -826,7 +826,7 @@ private static int AddValueToMetaData(List<byte> metaData, string value)
}
else
{
throw new ArgumentException(SR.Format(SR.EventSource_IllegalValue, value), "traits");
throw new ArgumentException(SR.Format(SR.EventSource_IllegalValue, value), nameof(value));
}

return metaData.Count - startPos;
Expand All@@ -850,7 +850,7 @@ private static int HexDigit(char c)
return c - 'A' + 10;
}

throw new ArgumentException(SR.Format(SR.EventSource_BadHexDigit, c), "traits");
throw new ArgumentException(SR.Format(SR.EventSource_BadHexDigit, c), nameof(c));
}

private NameInfo? UpdateDescriptor(
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -394,7 +394,7 @@ public virtual unsafe void Write(string value)
{
if (charStart < 0 || charCount < 0 || charStart > value.Length - charCount)
{
throw new ArgumentOutOfRangeException(nameof(charCount));
throw new ArgumentOutOfRangeException(nameof(value));
}
fixed (char* pChars = value)
{
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -415,7 +415,7 @@ public unsafe byte* PositionPointer
throw new IOException(SR.IO_SeekBeforeBegin);
long newPosition = (long)value - (long)_mem;
if (newPosition < 0)
throw new ArgumentOutOfRangeException("offset", SR.ArgumentOutOfRange_UnmanagedMemStreamLength);
throw new ArgumentOutOfRangeException(nameof(value), SR.ArgumentOutOfRange_UnmanagedMemStreamLength);

Interlocked.Exchange(ref _position, newPosition);
}
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -63,7 +63,7 @@ public static string ComputeDisplayName(string? name, Version? version, string?
if (pkt != null)
{
if (pkt.Length > PUBLIC_KEY_TOKEN_LEN)
throw new ArgumentException();
throw new ArgumentException(null, nameof(pkt));

sb.Append(", PublicKeyToken=");
if (pkt.Length == 0)
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -97,7 +97,7 @@ internal static unsafe int GetAnsiStringByteCount(ReadOnlySpan<char> chars)
byteLength = Interop.Kernel32.WideCharToMultiByte(
Interop.Kernel32.CP_ACP, Interop.Kernel32.WC_NO_BEST_FIT_CHARS, pChars, chars.Length, null, 0, IntPtr.Zero, IntPtr.Zero);
if (byteLength <= 0)
throw new ArgumentException();
throw new ArgumentException(null, nameof(chars));
}
}

Expand All@@ -121,7 +121,7 @@ internal static unsafe void GetAnsiStringBytes(ReadOnlySpan<char> chars, Span<by
byteLength = Interop.Kernel32.WideCharToMultiByte(
Interop.Kernel32.CP_ACP, Interop.Kernel32.WC_NO_BEST_FIT_CHARS, pChars, chars.Length, pBytes, bytes.Length, IntPtr.Zero, IntPtr.Zero);
if (byteLength <= 0)
throw new ArgumentException();
throw new ArgumentException(null, nameof(bytes));
}
}

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -109,7 +109,7 @@ internal EncoderFallbackException(
}
if (!char.IsLowSurrogate(charUnknownLow))
{
throw new ArgumentOutOfRangeException(nameof(CharUnknownLow),
throw new ArgumentOutOfRangeException(nameof(charUnknownLow),
SR.Format(SR.ArgumentOutOfRange_Range, 0xDC00, 0xDFFF));
}

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -961,7 +961,7 @@ private StringBuilder AppendCore(StringBuilder value, int startIndex, int count)

if ((uint)newLength > (uint)m_MaxCapacity)
{
throw new ArgumentOutOfRangeException(nameof(Capacity), SR.ArgumentOutOfRange_Capacity);
throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_Capacity);
}

while (count > 0)
Expand DownExpand Up@@ -1144,7 +1144,9 @@ public StringBuilder Remove(int startIndex, int length)
return this;
}

#pragma warning disable CA1830 // Prefer strongly-typed Append and Insert method overloads on StringBuilder.
public StringBuilder Append(bool value) => Append(value.ToString());
#pragma warning restore CA1830 // Prefer strongly-typed Append and Insert method overloads on StringBuilder.

public StringBuilder Append(char value)
{
Expand DownExpand Up@@ -2401,7 +2403,7 @@ private void ExpandByABlock(int minBlockCharCount)

if ((minBlockCharCount + Length) > m_MaxCapacity || minBlockCharCount + Length < minBlockCharCount)
{
throw new ArgumentOutOfRangeException("requiredLength", SR.ArgumentOutOfRange_SmallCapacity);
throw new ArgumentOutOfRangeException(nameof(minBlockCharCount), SR.ArgumentOutOfRange_SmallCapacity);
}

// - We always need to make the new chunk at least as big as was requested (`minBlockCharCount`).
Expand DownExpand Up@@ -2490,7 +2492,7 @@ private void MakeRoom(int index, int count, out StringBuilder chunk, out int ind

if (count + Length > m_MaxCapacity || count + Length < count)
{
throw new ArgumentOutOfRangeException("requiredLength", SR.ArgumentOutOfRange_SmallCapacity);
throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_SmallCapacity);
}

chunk = this;
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -243,7 +243,7 @@ public bool TrySetApartmentState(ApartmentState state)
break;

default:
throw new ArgumentOutOfRangeException(SR.ArgumentOutOfRange_Enum, nameof(state));
throw new ArgumentOutOfRangeException(nameof(state), SR.ArgumentOutOfRange_Enum);
}

return TrySetApartmentStateUnchecked(state);
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -165,7 +165,7 @@ public void GetRuntimeEvent()
});


Assert.Throws<ArgumentNullException>(null, () =>
Assert.Throws<ArgumentNullException>("name", () =>
{
typeof(RuntimeReflectionExtensionsTests).GetRuntimeEvent(null);
});
Expand DownExpand Up@@ -250,7 +250,7 @@ public void GetRuntimeField()
});


Assert.Throws<ArgumentNullException>(null, () =>
Assert.Throws<ArgumentNullException>("name", () =>
{
typeof(RuntimeReflectionExtensionsTests).GetRuntimeField(null);
});
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -40,7 +40,7 @@ public void Ctor_NullType_ThrowsNullReferenceException()
[Fact]
public void Ctor_NullEventName_ThrowsArgumentNullException()
{
AssertExtensions.Throws<ArgumentNullException>(null, () => new ComAwareEventInfo(typeof(NonComObject), null));
AssertExtensions.Throws<ArgumentNullException>("name", () => new ComAwareEventInfo(typeof(NonComObject), null));
}

[Fact]
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -186,8 +186,8 @@ public void OffsetOf_NullType_ThrowsArgumentNullException()
[Fact]
public void OffsetOf_NullFieldName_ThrowsArgumentNullException()
{
AssertExtensions.Throws<ArgumentNullException>(null, () => Marshal.OffsetOf(new object().GetType(), null));
AssertExtensions.Throws<ArgumentNullException>(null, () => Marshal.OffsetOf<object>(null));
AssertExtensions.Throws<ArgumentNullException>("name", () => Marshal.OffsetOf(new object().GetType(), null));
AssertExtensions.Throws<ArgumentNullException>("name", () => Marshal.OffsetOf<object>(null));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If Marshal.OffsetOf were a more entry-level method, I'd advocate taking a change for it to validate the field name directly so it could throw the ANE with the correct parameter name ("fieldName"). But I'm guessing our position right now is "it's an advanced enough API that the caller is expected to realize the parameter sharing between OffsetOf's fieldName and GetField's name."

Writing this down in case someone else is iffy about it and wants to have the discussion. But currently sighing and not recommending further action.

}

[Fact]
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Closed
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
2 changes: 1 addition & 1 deletion eng/CodeAnalysis.ruleset
Original file line numberDiff line numberDiff line change
Expand Up@@ -106,7 +106,7 @@
<Rule Id="CA2200" Action="Warning" /> <!-- Rethrow to preserve stack details. -->
<Rule Id="CA2201" Action="None" /> <!-- Do not raise reserved exception types -->
<Rule Id="CA2207" Action="Warning" /> <!-- Initialize value type static fields inline -->
<Rule Id="CA2208" Action="None" /> <!-- Instantiate argument exceptions correctly -->
<Rule Id="CA2208" Action="Info" /> <!-- Instantiate argument exceptions correctly -->

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would have thought we wanted Warnings here (with everything fixed or suppressed by this PR)

@buyaa-nbuyaa-nApr 20, 2020

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have discussed to upgrade severity level from hidden to info, so I thought I should make it same here, but yes maybe we want to make it warning to get full benefit, we might need lots of suppress though

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Talked with @bartonjs we will make it warning after fixing/suppressing all warnings. For now, I will leave this PR on hold until applying his suggestions on improving analyzer:

  • maybe we only want the analyzer to report for public/protected/protected ( do not warn for internal private methods).
  • We could include the generic method parameters (and possibly the generic type parameters for constructors) as legal targets.

Then we might have much less warning need to fix/suppress, and i might update this PR with all repo fix (coreclr+libs+mono)

<Rule Id="CA2211" Action="None" /> <!-- Non-constant fields should not be visible -->
<Rule Id="CA2213" Action="None" /> <!-- Disposable fields should be disposed -->
<Rule Id="CA2214" Action="None" /> <!-- Do not call overridable methods in constructors -->
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -124,7 +124,7 @@ public static object GetClassFactoryForType(ComActivationContext cxt)

if (!Path.IsPathRooted(cxt.AssemblyPath))
{
throw new ArgumentException();
throw new ArgumentException(null, nameof(cxt));
Comment thread
AaronRobinsonMSFT marked this conversation as resolved.
}

Type classType = FindClassType(cxt.ClassId, cxt.AssemblyPath, cxt.AssemblyName, cxt.TypeName);
Expand DownExpand Up@@ -156,7 +156,7 @@ public static void ClassRegistrationScenarioForType(ComActivationContext cxt, bo

if (!Path.IsPathRooted(cxt.AssemblyPath))
{
throw new ArgumentException();
throw new ArgumentException(null, nameof(cxt));
}

Type classType = FindClassType(cxt.ClassId, cxt.AssemblyPath, cxt.AssemblyName, cxt.TypeName);
Expand DownExpand Up@@ -288,7 +288,7 @@ public static unsafe int RegisterClassForTypeInternal(ComActivationContextIntern
if (cxtInt.InterfaceId != Guid.Empty
|| cxtInt.ClassFactoryDest != IntPtr.Zero)
{
throw new ArgumentException();
throw new ArgumentException(null, nameof(pCxtInt));
}

try
Expand DownExpand Up@@ -328,7 +328,7 @@ public static unsafe int UnregisterClassForTypeInternal(ComActivationContextInte
if (cxtInt.InterfaceId != Guid.Empty
|| cxtInt.ClassFactoryDest != IntPtr.Zero)
{
throw new ArgumentException();
throw new ArgumentException(null, nameof(pCxtInt));
}

try
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/src/System.Private.CoreLib/src/System/GC.cs
Original file line numberDiff line numberDiff line change
Expand Up@@ -135,7 +135,7 @@ public static void AddMemoryPressure(long bytesAllocated)

if ((4 == IntPtr.Size) && (bytesAllocated > int.MaxValue))
{
throw new ArgumentOutOfRangeException("pressure",
throw new ArgumentOutOfRangeException(nameof(bytesAllocated),
SR.ArgumentOutOfRange_MustBeNonNegInt32);
}

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -121,7 +121,7 @@ public IntPtr GetOrCreateComInterfaceForObject(object instance, CreateComInterfa
{
IntPtr ptr;
if (!TryGetOrCreateComInterfaceForObjectInternal(this, instance, flags, out ptr))
throw new ArgumentException();
throw new ArgumentException(null, nameof(instance));

return ptr;
}
Expand DownExpand Up@@ -187,7 +187,7 @@ public object GetOrCreateObjectForComInstance(IntPtr externalComObject, CreateOb
{
object? obj;
if (!TryGetOrCreateObjectForComInstanceInternal(this, externalComObject, flags, null, out obj))
throw new ArgumentNullException();
throw new ArgumentNullException(nameof(externalComObject));

return obj!;
}
Expand DownExpand Up@@ -230,7 +230,7 @@ public object GetOrRegisterObjectForComInstance(IntPtr externalComObject, Create

object? obj;
if (!TryGetOrCreateObjectForComInstanceInternal(this, externalComObject, flags, wrapper, out obj))
throw new ArgumentNullException();
throw new ArgumentNullException(nameof(externalComObject));

return obj!;
}
Expand DownExpand Up@@ -319,4 +319,4 @@ internal static int CallICustomQueryInterface(object customQueryInterfaceMaybe,
return (int)customQueryInterface.GetInterface(ref iid, out ppObject);
}
}
}
}
Original file line numberDiff line numberDiff line change
Expand Up@@ -1896,7 +1896,7 @@ private static void ThrowIfTypeNeverValidGenericArgument(RuntimeType type)
internal static void SanityCheckGenericArguments(RuntimeType[] genericArguments, RuntimeType[] genericParamters)
{
if (genericArguments == null)
throw new ArgumentNullException();
throw new ArgumentNullException(nameof(genericArguments));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

genericArguments was never supplied by the user. As such, maybe this code ought to not throw at all (just let it throw NRE). But, not suggesting you change it.


for (int i = 0; i < genericArguments.Length; i++)
{
Expand DownExpand Up@@ -2752,7 +2752,7 @@ public override InterfaceMapping GetInterfaceMap(Type ifaceType)
protected override PropertyInfo? GetPropertyImpl(
string name, BindingFlags bindingAttr, Binder? binder, Type? returnType, Type[]? types, ParameterModifier[]? modifiers)
{
if (name == null) throw new ArgumentNullException();
if (name == null) throw new ArgumentNullException(nameof(name));

ListBuilder<PropertyInfo> candidates = GetPropertyCandidates(name, bindingAttr, types, false);

Expand DownExpand Up@@ -2788,7 +2788,7 @@ public override InterfaceMapping GetInterfaceMap(Type ifaceType)

public override EventInfo? GetEvent(string name, BindingFlags bindingAttr)
{
if (name is null) throw new ArgumentNullException();
if (name is null) throw new ArgumentNullException(nameof(name));

FilterHelper(bindingAttr, ref name, out _, out MemberListType listType);

Expand All@@ -2814,7 +2814,7 @@ public override InterfaceMapping GetInterfaceMap(Type ifaceType)

public override FieldInfo? GetField(string name, BindingFlags bindingAttr)
{
if (name is null) throw new ArgumentNullException();
if (name is null) throw new ArgumentNullException(nameof(name));

FilterHelper(bindingAttr, ref name, out _, out MemberListType listType);

Expand DownExpand Up@@ -2851,7 +2851,7 @@ public override InterfaceMapping GetInterfaceMap(Type ifaceType)

public override Type? GetInterface(string fullname, bool ignoreCase)
{
if (fullname is null) throw new ArgumentNullException();
if (fullname is null) throw new ArgumentNullException(nameof(fullname));

BindingFlags bindingAttr = BindingFlags.Public | BindingFlags.NonPublic;

Expand DownExpand Up@@ -2885,7 +2885,7 @@ public override InterfaceMapping GetInterfaceMap(Type ifaceType)

public override Type? GetNestedType(string fullname, BindingFlags bindingAttr)
{
if (fullname is null) throw new ArgumentNullException();
if (fullname is null) throw new ArgumentNullException(nameof(fullname));

bindingAttr &= ~BindingFlags.Static;
string name, ns;
Expand DownExpand Up@@ -2913,7 +2913,7 @@ public override InterfaceMapping GetInterfaceMap(Type ifaceType)

public override MemberInfo[] GetMember(string name, MemberTypes type, BindingFlags bindingAttr)
{
if (name is null) throw new ArgumentNullException();
if (name is null) throw new ArgumentNullException(nameof(name));

ListBuilder<MethodInfo> methods = default;
ListBuilder<ConstructorInfo> constructors = default;
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -287,7 +287,7 @@ bool compressStack
}
else
{
Comment thread
buyaa-n marked this conversation as resolved.
throw new ArgumentNullException(nameof(WaitOrTimerCallback));
throw new ArgumentNullException(nameof(callBack));
}
return registeredWaitHandle;
}
Expand Down
4 changes: 2 additions & 2 deletions src/libraries/Common/src/System/Threading/Tasks/TaskToApm.cs
Original file line numberDiff line numberDiff line change
Expand Up@@ -43,7 +43,7 @@ public static void End(IAsyncResult asyncResult)
return;
}

throw new ArgumentNullException();
throw new ArgumentNullException(nameof(asyncResult));
}

/// <summary>Processes an IAsyncResult returned by Begin.</summary>
Expand All@@ -55,7 +55,7 @@ public static TResult End<TResult>(IAsyncResult asyncResult)
return task.GetAwaiter().GetResult();
}

throw new ArgumentNullException();
throw new ArgumentNullException(nameof(asyncResult));
}

/// <summary>Provides a simple IAsyncResult that wraps a Task.</summary>
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -32,12 +32,12 @@ internal DiagnosticCounter(string name, EventSource eventSource)
{
if (name == null)
{
throw new ArgumentNullException(nameof(Name));
throw new ArgumentNullException(nameof(name));
}

if (eventSource == null)
{
throw new ArgumentNullException(nameof(EventSource));
throw new ArgumentNullException(nameof(eventSource));
}

Name = name;
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -262,7 +262,7 @@ private void Write<T>(EventSource eventSource, string? eventName, ref EventSourc
if (this.state != State.Started)
throw new InvalidOperationException(); // Write after stop.
if (eventName == null)
throw new ArgumentNullException();
throw new ArgumentNullException(nameof(eventName));

eventSource.Write(eventName, ref options, ref this.activityId, ref s_empty, ref data);
}
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -813,7 +813,7 @@ private static int AddValueToMetaData(List<byte> metaData, string value)
{
if (!(i + 1 < value.Length))
{
throw new ArgumentException(SR.EventSource_EvenHexDigits, "traits");
throw new ArgumentException(SR.EventSource_EvenHexDigits, nameof(value));
}
metaData.Add((byte)(HexDigit(value[i]) * 16 + HexDigit(value[i + 1])));
i++;
Expand All@@ -826,7 +826,7 @@ private static int AddValueToMetaData(List<byte> metaData, string value)
}
else
{
throw new ArgumentException(SR.Format(SR.EventSource_IllegalValue, value), "traits");
throw new ArgumentException(SR.Format(SR.EventSource_IllegalValue, value), nameof(value));
}

return metaData.Count - startPos;
Expand All@@ -850,7 +850,7 @@ private static int HexDigit(char c)
return c - 'A' + 10;
}

throw new ArgumentException(SR.Format(SR.EventSource_BadHexDigit, c), "traits");
throw new ArgumentException(SR.Format(SR.EventSource_BadHexDigit, c), nameof(c));
}

private NameInfo? UpdateDescriptor(
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -394,7 +394,7 @@ public virtual unsafe void Write(string value)
{
if (charStart < 0 || charCount < 0 || charStart > value.Length - charCount)
{
throw new ArgumentOutOfRangeException(nameof(charCount));
throw new ArgumentOutOfRangeException(nameof(value));
}
fixed (char* pChars = value)
{
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -415,7 +415,7 @@ public unsafe byte* PositionPointer
throw new IOException(SR.IO_SeekBeforeBegin);
long newPosition = (long)value - (long)_mem;
if (newPosition < 0)
throw new ArgumentOutOfRangeException("offset", SR.ArgumentOutOfRange_UnmanagedMemStreamLength);
throw new ArgumentOutOfRangeException(nameof(value), SR.ArgumentOutOfRange_UnmanagedMemStreamLength);

Interlocked.Exchange(ref _position, newPosition);
}
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -63,7 +63,7 @@ public static string ComputeDisplayName(string? name, Version? version, string?
if (pkt != null)
{
if (pkt.Length > PUBLIC_KEY_TOKEN_LEN)
throw new ArgumentException();
throw new ArgumentException(null, nameof(pkt));

sb.Append(", PublicKeyToken=");
if (pkt.Length == 0)
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -97,7 +97,7 @@ internal static unsafe int GetAnsiStringByteCount(ReadOnlySpan<char> chars)
byteLength = Interop.Kernel32.WideCharToMultiByte(
Interop.Kernel32.CP_ACP, Interop.Kernel32.WC_NO_BEST_FIT_CHARS, pChars, chars.Length, null, 0, IntPtr.Zero, IntPtr.Zero);
if (byteLength <= 0)
throw new ArgumentException();
throw new ArgumentException(null, nameof(chars));
}
}

Expand All@@ -121,7 +121,7 @@ internal static unsafe void GetAnsiStringBytes(ReadOnlySpan<char> chars, Span<by
byteLength = Interop.Kernel32.WideCharToMultiByte(
Interop.Kernel32.CP_ACP, Interop.Kernel32.WC_NO_BEST_FIT_CHARS, pChars, chars.Length, pBytes, bytes.Length, IntPtr.Zero, IntPtr.Zero);
if (byteLength <= 0)
throw new ArgumentException();
throw new ArgumentException(null, nameof(bytes));
}
}

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -109,7 +109,7 @@ internal EncoderFallbackException(
}
if (!char.IsLowSurrogate(charUnknownLow))
{
throw new ArgumentOutOfRangeException(nameof(CharUnknownLow),
throw new ArgumentOutOfRangeException(nameof(charUnknownLow),
SR.Format(SR.ArgumentOutOfRange_Range, 0xDC00, 0xDFFF));
}

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -961,7 +961,7 @@ private StringBuilder AppendCore(StringBuilder value, int startIndex, int count)

if ((uint)newLength > (uint)m_MaxCapacity)
{
throw new ArgumentOutOfRangeException(nameof(Capacity), SR.ArgumentOutOfRange_Capacity);
throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_Capacity);
}

while (count > 0)
Expand DownExpand Up@@ -1144,7 +1144,9 @@ public StringBuilder Remove(int startIndex, int length)
return this;
}

#pragma warning disable CA1830 // Prefer strongly-typed Append and Insert method overloads on StringBuilder.
public StringBuilder Append(bool value) => Append(value.ToString());
#pragma warning restore CA1830 // Prefer strongly-typed Append and Insert method overloads on StringBuilder.

public StringBuilder Append(char value)
{
Expand DownExpand Up@@ -2401,7 +2403,7 @@ private void ExpandByABlock(int minBlockCharCount)

if ((minBlockCharCount + Length) > m_MaxCapacity || minBlockCharCount + Length < minBlockCharCount)
{
throw new ArgumentOutOfRangeException("requiredLength", SR.ArgumentOutOfRange_SmallCapacity);
throw new ArgumentOutOfRangeException(nameof(minBlockCharCount), SR.ArgumentOutOfRange_SmallCapacity);
}

// - We always need to make the new chunk at least as big as was requested (`minBlockCharCount`).
Expand DownExpand Up@@ -2490,7 +2492,7 @@ private void MakeRoom(int index, int count, out StringBuilder chunk, out int ind

if (count + Length > m_MaxCapacity || count + Length < count)
{
throw new ArgumentOutOfRangeException("requiredLength", SR.ArgumentOutOfRange_SmallCapacity);
throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_SmallCapacity);
}

chunk = this;
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -243,7 +243,7 @@ public bool TrySetApartmentState(ApartmentState state)
break;

default:
throw new ArgumentOutOfRangeException(SR.ArgumentOutOfRange_Enum, nameof(state));
throw new ArgumentOutOfRangeException(nameof(state), SR.ArgumentOutOfRange_Enum);
}

return TrySetApartmentStateUnchecked(state);
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -165,7 +165,7 @@ public void GetRuntimeEvent()
});


Assert.Throws<ArgumentNullException>(null, () =>
Assert.Throws<ArgumentNullException>("name", () =>
{
typeof(RuntimeReflectionExtensionsTests).GetRuntimeEvent(null);
});
Expand DownExpand Up@@ -250,7 +250,7 @@ public void GetRuntimeField()
});


Assert.Throws<ArgumentNullException>(null, () =>
Assert.Throws<ArgumentNullException>("name", () =>
{
typeof(RuntimeReflectionExtensionsTests).GetRuntimeField(null);
});
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -40,7 +40,7 @@ public void Ctor_NullType_ThrowsNullReferenceException()
[Fact]
public void Ctor_NullEventName_ThrowsArgumentNullException()
{
AssertExtensions.Throws<ArgumentNullException>(null, () => new ComAwareEventInfo(typeof(NonComObject), null));
AssertExtensions.Throws<ArgumentNullException>("name", () => new ComAwareEventInfo(typeof(NonComObject), null));
}

[Fact]
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -186,8 +186,8 @@ public void OffsetOf_NullType_ThrowsArgumentNullException()
[Fact]
public void OffsetOf_NullFieldName_ThrowsArgumentNullException()
{
AssertExtensions.Throws<ArgumentNullException>(null, () => Marshal.OffsetOf(new object().GetType(), null));
AssertExtensions.Throws<ArgumentNullException>(null, () => Marshal.OffsetOf<object>(null));
AssertExtensions.Throws<ArgumentNullException>("name", () => Marshal.OffsetOf(new object().GetType(), null));
AssertExtensions.Throws<ArgumentNullException>("name", () => Marshal.OffsetOf<object>(null));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If Marshal.OffsetOf were a more entry-level method, I'd advocate taking a change for it to validate the field name directly so it could throw the ANE with the correct parameter name ("fieldName"). But I'm guessing our position right now is "it's an advanced enough API that the caller is expected to realize the parameter sharing between OffsetOf's fieldName and GetField's name."

Writing this down in case someone else is iffy about it and wants to have the discussion. But currently sighing and not recommending further action.

}

[Fact]
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Closed
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
2 changes: 1 addition & 1 deletion eng/CodeAnalysis.ruleset
Original file line numberDiff line numberDiff line change
Expand Up@@ -106,7 +106,7 @@
<Rule Id="CA2200" Action="Warning" /> <!-- Rethrow to preserve stack details. -->
<Rule Id="CA2201" Action="None" /> <!-- Do not raise reserved exception types -->
<Rule Id="CA2207" Action="Warning" /> <!-- Initialize value type static fields inline -->
<Rule Id="CA2208" Action="None" /> <!-- Instantiate argument exceptions correctly -->
<Rule Id="CA2208" Action="Info" /> <!-- Instantiate argument exceptions correctly -->

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would have thought we wanted Warnings here (with everything fixed or suppressed by this PR)

@buyaa-nbuyaa-nApr 20, 2020

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have discussed to upgrade severity level from hidden to info, so I thought I should make it same here, but yes maybe we want to make it warning to get full benefit, we might need lots of suppress though

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Talked with @bartonjs we will make it warning after fixing/suppressing all warnings. For now, I will leave this PR on hold until applying his suggestions on improving analyzer:

  • maybe we only want the analyzer to report for public/protected/protected ( do not warn for internal private methods).
  • We could include the generic method parameters (and possibly the generic type parameters for constructors) as legal targets.

Then we might have much less warning need to fix/suppress, and i might update this PR with all repo fix (coreclr+libs+mono)

<Rule Id="CA2211" Action="None" /> <!-- Non-constant fields should not be visible -->
<Rule Id="CA2213" Action="None" /> <!-- Disposable fields should be disposed -->
<Rule Id="CA2214" Action="None" /> <!-- Do not call overridable methods in constructors -->
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -124,7 +124,7 @@ public static object GetClassFactoryForType(ComActivationContext cxt)

if (!Path.IsPathRooted(cxt.AssemblyPath))
{
throw new ArgumentException();
throw new ArgumentException(null, nameof(cxt));
Comment thread
AaronRobinsonMSFT marked this conversation as resolved.
}

Type classType = FindClassType(cxt.ClassId, cxt.AssemblyPath, cxt.AssemblyName, cxt.TypeName);
Expand DownExpand Up@@ -156,7 +156,7 @@ public static void ClassRegistrationScenarioForType(ComActivationContext cxt, bo

if (!Path.IsPathRooted(cxt.AssemblyPath))
{
throw new ArgumentException();
throw new ArgumentException(null, nameof(cxt));
}

Type classType = FindClassType(cxt.ClassId, cxt.AssemblyPath, cxt.AssemblyName, cxt.TypeName);
Expand DownExpand Up@@ -288,7 +288,7 @@ public static unsafe int RegisterClassForTypeInternal(ComActivationContextIntern
if (cxtInt.InterfaceId != Guid.Empty
|| cxtInt.ClassFactoryDest != IntPtr.Zero)
{
throw new ArgumentException();
throw new ArgumentException(null, nameof(pCxtInt));
}

try
Expand DownExpand Up@@ -328,7 +328,7 @@ public static unsafe int UnregisterClassForTypeInternal(ComActivationContextInte
if (cxtInt.InterfaceId != Guid.Empty
|| cxtInt.ClassFactoryDest != IntPtr.Zero)
{
throw new ArgumentException();
throw new ArgumentException(null, nameof(pCxtInt));
}

try
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/src/System.Private.CoreLib/src/System/GC.cs
Original file line numberDiff line numberDiff line change
Expand Up@@ -135,7 +135,7 @@ public static void AddMemoryPressure(long bytesAllocated)

if ((4 == IntPtr.Size) && (bytesAllocated > int.MaxValue))
{
throw new ArgumentOutOfRangeException("pressure",
throw new ArgumentOutOfRangeException(nameof(bytesAllocated),
SR.ArgumentOutOfRange_MustBeNonNegInt32);
}

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -121,7 +121,7 @@ public IntPtr GetOrCreateComInterfaceForObject(object instance, CreateComInterfa
{
IntPtr ptr;
if (!TryGetOrCreateComInterfaceForObjectInternal(this, instance, flags, out ptr))
throw new ArgumentException();
throw new ArgumentException(null, nameof(instance));

return ptr;
}
Expand DownExpand Up@@ -187,7 +187,7 @@ public object GetOrCreateObjectForComInstance(IntPtr externalComObject, CreateOb
{
object? obj;
if (!TryGetOrCreateObjectForComInstanceInternal(this, externalComObject, flags, null, out obj))
throw new ArgumentNullException();
throw new ArgumentNullException(nameof(externalComObject));

return obj!;
}
Expand DownExpand Up@@ -230,7 +230,7 @@ public object GetOrRegisterObjectForComInstance(IntPtr externalComObject, Create

object? obj;
if (!TryGetOrCreateObjectForComInstanceInternal(this, externalComObject, flags, wrapper, out obj))
throw new ArgumentNullException();
throw new ArgumentNullException(nameof(externalComObject));

return obj!;
}
Expand DownExpand Up@@ -319,4 +319,4 @@ internal static int CallICustomQueryInterface(object customQueryInterfaceMaybe,
return (int)customQueryInterface.GetInterface(ref iid, out ppObject);
}
}
}
}
Original file line numberDiff line numberDiff line change
Expand Up@@ -1896,7 +1896,7 @@ private static void ThrowIfTypeNeverValidGenericArgument(RuntimeType type)
internal static void SanityCheckGenericArguments(RuntimeType[] genericArguments, RuntimeType[] genericParamters)
{
if (genericArguments == null)
throw new ArgumentNullException();
throw new ArgumentNullException(nameof(genericArguments));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

genericArguments was never supplied by the user. As such, maybe this code ought to not throw at all (just let it throw NRE). But, not suggesting you change it.


for (int i = 0; i < genericArguments.Length; i++)
{
Expand DownExpand Up@@ -2752,7 +2752,7 @@ public override InterfaceMapping GetInterfaceMap(Type ifaceType)
protected override PropertyInfo? GetPropertyImpl(
string name, BindingFlags bindingAttr, Binder? binder, Type? returnType, Type[]? types, ParameterModifier[]? modifiers)
{
if (name == null) throw new ArgumentNullException();
if (name == null) throw new ArgumentNullException(nameof(name));

ListBuilder<PropertyInfo> candidates = GetPropertyCandidates(name, bindingAttr, types, false);

Expand DownExpand Up@@ -2788,7 +2788,7 @@ public override InterfaceMapping GetInterfaceMap(Type ifaceType)

public override EventInfo? GetEvent(string name, BindingFlags bindingAttr)
{
if (name is null) throw new ArgumentNullException();
if (name is null) throw new ArgumentNullException(nameof(name));

FilterHelper(bindingAttr, ref name, out _, out MemberListType listType);

Expand All@@ -2814,7 +2814,7 @@ public override InterfaceMapping GetInterfaceMap(Type ifaceType)

public override FieldInfo? GetField(string name, BindingFlags bindingAttr)
{
if (name is null) throw new ArgumentNullException();
if (name is null) throw new ArgumentNullException(nameof(name));

FilterHelper(bindingAttr, ref name, out _, out MemberListType listType);

Expand DownExpand Up@@ -2851,7 +2851,7 @@ public override InterfaceMapping GetInterfaceMap(Type ifaceType)

public override Type? GetInterface(string fullname, bool ignoreCase)
{
if (fullname is null) throw new ArgumentNullException();
if (fullname is null) throw new ArgumentNullException(nameof(fullname));

BindingFlags bindingAttr = BindingFlags.Public | BindingFlags.NonPublic;

Expand DownExpand Up@@ -2885,7 +2885,7 @@ public override InterfaceMapping GetInterfaceMap(Type ifaceType)

public override Type? GetNestedType(string fullname, BindingFlags bindingAttr)
{
if (fullname is null) throw new ArgumentNullException();
if (fullname is null) throw new ArgumentNullException(nameof(fullname));

bindingAttr &= ~BindingFlags.Static;
string name, ns;
Expand DownExpand Up@@ -2913,7 +2913,7 @@ public override InterfaceMapping GetInterfaceMap(Type ifaceType)

public override MemberInfo[] GetMember(string name, MemberTypes type, BindingFlags bindingAttr)
{
if (name is null) throw new ArgumentNullException();
if (name is null) throw new ArgumentNullException(nameof(name));

ListBuilder<MethodInfo> methods = default;
ListBuilder<ConstructorInfo> constructors = default;
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -287,7 +287,7 @@ bool compressStack
}
else
{
Comment thread
buyaa-n marked this conversation as resolved.
throw new ArgumentNullException(nameof(WaitOrTimerCallback));
throw new ArgumentNullException(nameof(callBack));
}
return registeredWaitHandle;
}
Expand Down
4 changes: 2 additions & 2 deletions src/libraries/Common/src/System/Threading/Tasks/TaskToApm.cs
Original file line numberDiff line numberDiff line change
Expand Up@@ -43,7 +43,7 @@ public static void End(IAsyncResult asyncResult)
return;
}

throw new ArgumentNullException();
throw new ArgumentNullException(nameof(asyncResult));
}

/// <summary>Processes an IAsyncResult returned by Begin.</summary>
Expand All@@ -55,7 +55,7 @@ public static TResult End<TResult>(IAsyncResult asyncResult)
return task.GetAwaiter().GetResult();
}

throw new ArgumentNullException();
throw new ArgumentNullException(nameof(asyncResult));
}

/// <summary>Provides a simple IAsyncResult that wraps a Task.</summary>
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -32,12 +32,12 @@ internal DiagnosticCounter(string name, EventSource eventSource)
{
if (name == null)
{
throw new ArgumentNullException(nameof(Name));
throw new ArgumentNullException(nameof(name));
}

if (eventSource == null)
{
throw new ArgumentNullException(nameof(EventSource));
throw new ArgumentNullException(nameof(eventSource));
}

Name = name;
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -262,7 +262,7 @@ private void Write<T>(EventSource eventSource, string? eventName, ref EventSourc
if (this.state != State.Started)
throw new InvalidOperationException(); // Write after stop.
if (eventName == null)
throw new ArgumentNullException();
throw new ArgumentNullException(nameof(eventName));

eventSource.Write(eventName, ref options, ref this.activityId, ref s_empty, ref data);
}
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -813,7 +813,7 @@ private static int AddValueToMetaData(List<byte> metaData, string value)
{
if (!(i + 1 < value.Length))
{
throw new ArgumentException(SR.EventSource_EvenHexDigits, "traits");
throw new ArgumentException(SR.EventSource_EvenHexDigits, nameof(value));
}
metaData.Add((byte)(HexDigit(value[i]) * 16 + HexDigit(value[i + 1])));
i++;
Expand All@@ -826,7 +826,7 @@ private static int AddValueToMetaData(List<byte> metaData, string value)
}
else
{
throw new ArgumentException(SR.Format(SR.EventSource_IllegalValue, value), "traits");
throw new ArgumentException(SR.Format(SR.EventSource_IllegalValue, value), nameof(value));
}

return metaData.Count - startPos;
Expand All@@ -850,7 +850,7 @@ private static int HexDigit(char c)
return c - 'A' + 10;
}

throw new ArgumentException(SR.Format(SR.EventSource_BadHexDigit, c), "traits");
throw new ArgumentException(SR.Format(SR.EventSource_BadHexDigit, c), nameof(c));
}

private NameInfo? UpdateDescriptor(
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -394,7 +394,7 @@ public virtual unsafe void Write(string value)
{
if (charStart < 0 || charCount < 0 || charStart > value.Length - charCount)
{
throw new ArgumentOutOfRangeException(nameof(charCount));
throw new ArgumentOutOfRangeException(nameof(value));
}
fixed (char* pChars = value)
{
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -415,7 +415,7 @@ public unsafe byte* PositionPointer
throw new IOException(SR.IO_SeekBeforeBegin);
long newPosition = (long)value - (long)_mem;
if (newPosition < 0)
throw new ArgumentOutOfRangeException("offset", SR.ArgumentOutOfRange_UnmanagedMemStreamLength);
throw new ArgumentOutOfRangeException(nameof(value), SR.ArgumentOutOfRange_UnmanagedMemStreamLength);

Interlocked.Exchange(ref _position, newPosition);
}
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -63,7 +63,7 @@ public static string ComputeDisplayName(string? name, Version? version, string?
if (pkt != null)
{
if (pkt.Length > PUBLIC_KEY_TOKEN_LEN)
throw new ArgumentException();
throw new ArgumentException(null, nameof(pkt));

sb.Append(", PublicKeyToken=");
if (pkt.Length == 0)
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -97,7 +97,7 @@ internal static unsafe int GetAnsiStringByteCount(ReadOnlySpan<char> chars)
byteLength = Interop.Kernel32.WideCharToMultiByte(
Interop.Kernel32.CP_ACP, Interop.Kernel32.WC_NO_BEST_FIT_CHARS, pChars, chars.Length, null, 0, IntPtr.Zero, IntPtr.Zero);
if (byteLength <= 0)
throw new ArgumentException();
throw new ArgumentException(null, nameof(chars));
}
}

Expand All@@ -121,7 +121,7 @@ internal static unsafe void GetAnsiStringBytes(ReadOnlySpan<char> chars, Span<by
byteLength = Interop.Kernel32.WideCharToMultiByte(
Interop.Kernel32.CP_ACP, Interop.Kernel32.WC_NO_BEST_FIT_CHARS, pChars, chars.Length, pBytes, bytes.Length, IntPtr.Zero, IntPtr.Zero);
if (byteLength <= 0)
throw new ArgumentException();
throw new ArgumentException(null, nameof(bytes));
}
}

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -109,7 +109,7 @@ internal EncoderFallbackException(
}
if (!char.IsLowSurrogate(charUnknownLow))
{
throw new ArgumentOutOfRangeException(nameof(CharUnknownLow),
throw new ArgumentOutOfRangeException(nameof(charUnknownLow),
SR.Format(SR.ArgumentOutOfRange_Range, 0xDC00, 0xDFFF));
}

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -961,7 +961,7 @@ private StringBuilder AppendCore(StringBuilder value, int startIndex, int count)

if ((uint)newLength > (uint)m_MaxCapacity)
{
throw new ArgumentOutOfRangeException(nameof(Capacity), SR.ArgumentOutOfRange_Capacity);
throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_Capacity);
}

while (count > 0)
Expand DownExpand Up@@ -1144,7 +1144,9 @@ public StringBuilder Remove(int startIndex, int length)
return this;
}

#pragma warning disable CA1830 // Prefer strongly-typed Append and Insert method overloads on StringBuilder.
public StringBuilder Append(bool value) => Append(value.ToString());
#pragma warning restore CA1830 // Prefer strongly-typed Append and Insert method overloads on StringBuilder.

public StringBuilder Append(char value)
{
Expand DownExpand Up@@ -2401,7 +2403,7 @@ private void ExpandByABlock(int minBlockCharCount)

if ((minBlockCharCount + Length) > m_MaxCapacity || minBlockCharCount + Length < minBlockCharCount)
{
throw new ArgumentOutOfRangeException("requiredLength", SR.ArgumentOutOfRange_SmallCapacity);
throw new ArgumentOutOfRangeException(nameof(minBlockCharCount), SR.ArgumentOutOfRange_SmallCapacity);
}

// - We always need to make the new chunk at least as big as was requested (`minBlockCharCount`).
Expand DownExpand Up@@ -2490,7 +2492,7 @@ private void MakeRoom(int index, int count, out StringBuilder chunk, out int ind

if (count + Length > m_MaxCapacity || count + Length < count)
{
throw new ArgumentOutOfRangeException("requiredLength", SR.ArgumentOutOfRange_SmallCapacity);
throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_SmallCapacity);
}

chunk = this;
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -243,7 +243,7 @@ public bool TrySetApartmentState(ApartmentState state)
break;

default:
throw new ArgumentOutOfRangeException(SR.ArgumentOutOfRange_Enum, nameof(state));
throw new ArgumentOutOfRangeException(nameof(state), SR.ArgumentOutOfRange_Enum);
}

return TrySetApartmentStateUnchecked(state);
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -165,7 +165,7 @@ public void GetRuntimeEvent()
});


Assert.Throws<ArgumentNullException>(null, () =>
Assert.Throws<ArgumentNullException>("name", () =>
{
typeof(RuntimeReflectionExtensionsTests).GetRuntimeEvent(null);
});
Expand DownExpand Up@@ -250,7 +250,7 @@ public void GetRuntimeField()
});


Assert.Throws<ArgumentNullException>(null, () =>
Assert.Throws<ArgumentNullException>("name", () =>
{
typeof(RuntimeReflectionExtensionsTests).GetRuntimeField(null);
});
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -40,7 +40,7 @@ public void Ctor_NullType_ThrowsNullReferenceException()
[Fact]
public void Ctor_NullEventName_ThrowsArgumentNullException()
{
AssertExtensions.Throws<ArgumentNullException>(null, () => new ComAwareEventInfo(typeof(NonComObject), null));
AssertExtensions.Throws<ArgumentNullException>("name", () => new ComAwareEventInfo(typeof(NonComObject), null));
}

[Fact]
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -186,8 +186,8 @@ public void OffsetOf_NullType_ThrowsArgumentNullException()
[Fact]
public void OffsetOf_NullFieldName_ThrowsArgumentNullException()
{
AssertExtensions.Throws<ArgumentNullException>(null, () => Marshal.OffsetOf(new object().GetType(), null));
AssertExtensions.Throws<ArgumentNullException>(null, () => Marshal.OffsetOf<object>(null));
AssertExtensions.Throws<ArgumentNullException>("name", () => Marshal.OffsetOf(new object().GetType(), null));
AssertExtensions.Throws<ArgumentNullException>("name", () => Marshal.OffsetOf<object>(null));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If Marshal.OffsetOf were a more entry-level method, I'd advocate taking a change for it to validate the field name directly so it could throw the ANE with the correct parameter name ("fieldName"). But I'm guessing our position right now is "it's an advanced enough API that the caller is expected to realize the parameter sharing between OffsetOf's fieldName and GetField's name."

Writing this down in case someone else is iffy about it and wants to have the discussion. But currently sighing and not recommending further action.

}

[Fact]
Expand Down
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content
Closed
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
2 changes: 1 addition & 1 deletion eng/CodeAnalysis.ruleset
Original file line numberDiff line numberDiff line change
Expand Up@@ -106,7 +106,7 @@
<Rule Id="CA2200" Action="Warning" /> <!-- Rethrow to preserve stack details. -->
<Rule Id="CA2201" Action="None" /> <!-- Do not raise reserved exception types -->
<Rule Id="CA2207" Action="Warning" /> <!-- Initialize value type static fields inline -->
<Rule Id="CA2208" Action="None" /> <!-- Instantiate argument exceptions correctly -->
<Rule Id="CA2208" Action="Info" /> <!-- Instantiate argument exceptions correctly -->

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would have thought we wanted Warnings here (with everything fixed or suppressed by this PR)

@buyaa-nbuyaa-nApr 20, 2020

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have discussed to upgrade severity level from hidden to info, so I thought I should make it same here, but yes maybe we want to make it warning to get full benefit, we might need lots of suppress though

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Talked with @bartonjs we will make it warning after fixing/suppressing all warnings. For now, I will leave this PR on hold until applying his suggestions on improving analyzer:

  • maybe we only want the analyzer to report for public/protected/protected ( do not warn for internal private methods).
  • We could include the generic method parameters (and possibly the generic type parameters for constructors) as legal targets.

Then we might have much less warning need to fix/suppress, and i might update this PR with all repo fix (coreclr+libs+mono)

<Rule Id="CA2211" Action="None" /> <!-- Non-constant fields should not be visible -->
<Rule Id="CA2213" Action="None" /> <!-- Disposable fields should be disposed -->
<Rule Id="CA2214" Action="None" /> <!-- Do not call overridable methods in constructors -->
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -124,7 +124,7 @@ public static object GetClassFactoryForType(ComActivationContext cxt)

if (!Path.IsPathRooted(cxt.AssemblyPath))
{
throw new ArgumentException();
throw new ArgumentException(null, nameof(cxt));
Comment thread
AaronRobinsonMSFT marked this conversation as resolved.
}

Type classType = FindClassType(cxt.ClassId, cxt.AssemblyPath, cxt.AssemblyName, cxt.TypeName);
Expand DownExpand Up@@ -156,7 +156,7 @@ public static void ClassRegistrationScenarioForType(ComActivationContext cxt, bo

if (!Path.IsPathRooted(cxt.AssemblyPath))
{
throw new ArgumentException();
throw new ArgumentException(null, nameof(cxt));
}

Type classType = FindClassType(cxt.ClassId, cxt.AssemblyPath, cxt.AssemblyName, cxt.TypeName);
Expand DownExpand Up@@ -288,7 +288,7 @@ public static unsafe int RegisterClassForTypeInternal(ComActivationContextIntern
if (cxtInt.InterfaceId != Guid.Empty
|| cxtInt.ClassFactoryDest != IntPtr.Zero)
{
throw new ArgumentException();
throw new ArgumentException(null, nameof(pCxtInt));
}

try
Expand DownExpand Up@@ -328,7 +328,7 @@ public static unsafe int UnregisterClassForTypeInternal(ComActivationContextInte
if (cxtInt.InterfaceId != Guid.Empty
|| cxtInt.ClassFactoryDest != IntPtr.Zero)
{
throw new ArgumentException();
throw new ArgumentException(null, nameof(pCxtInt));
}

try
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/src/System.Private.CoreLib/src/System/GC.cs
Original file line numberDiff line numberDiff line change
Expand Up@@ -135,7 +135,7 @@ public static void AddMemoryPressure(long bytesAllocated)

if ((4 == IntPtr.Size) && (bytesAllocated > int.MaxValue))
{
throw new ArgumentOutOfRangeException("pressure",
throw new ArgumentOutOfRangeException(nameof(bytesAllocated),
SR.ArgumentOutOfRange_MustBeNonNegInt32);
}

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -121,7 +121,7 @@ public IntPtr GetOrCreateComInterfaceForObject(object instance, CreateComInterfa
{
IntPtr ptr;
if (!TryGetOrCreateComInterfaceForObjectInternal(this, instance, flags, out ptr))
throw new ArgumentException();
throw new ArgumentException(null, nameof(instance));

return ptr;
}
Expand DownExpand Up@@ -187,7 +187,7 @@ public object GetOrCreateObjectForComInstance(IntPtr externalComObject, CreateOb
{
object? obj;
if (!TryGetOrCreateObjectForComInstanceInternal(this, externalComObject, flags, null, out obj))
throw new ArgumentNullException();
throw new ArgumentNullException(nameof(externalComObject));

return obj!;
}
Expand DownExpand Up@@ -230,7 +230,7 @@ public object GetOrRegisterObjectForComInstance(IntPtr externalComObject, Create

object? obj;
if (!TryGetOrCreateObjectForComInstanceInternal(this, externalComObject, flags, wrapper, out obj))
throw new ArgumentNullException();
throw new ArgumentNullException(nameof(externalComObject));

return obj!;
}
Expand DownExpand Up@@ -319,4 +319,4 @@ internal static int CallICustomQueryInterface(object customQueryInterfaceMaybe,
return (int)customQueryInterface.GetInterface(ref iid, out ppObject);
}
}
}
}
Original file line numberDiff line numberDiff line change
Expand Up@@ -1896,7 +1896,7 @@ private static void ThrowIfTypeNeverValidGenericArgument(RuntimeType type)
internal static void SanityCheckGenericArguments(RuntimeType[] genericArguments, RuntimeType[] genericParamters)
{
if (genericArguments == null)
throw new ArgumentNullException();
throw new ArgumentNullException(nameof(genericArguments));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

genericArguments was never supplied by the user. As such, maybe this code ought to not throw at all (just let it throw NRE). But, not suggesting you change it.


for (int i = 0; i < genericArguments.Length; i++)
{
Expand DownExpand Up@@ -2752,7 +2752,7 @@ public override InterfaceMapping GetInterfaceMap(Type ifaceType)
protected override PropertyInfo? GetPropertyImpl(
string name, BindingFlags bindingAttr, Binder? binder, Type? returnType, Type[]? types, ParameterModifier[]? modifiers)
{
if (name == null) throw new ArgumentNullException();
if (name == null) throw new ArgumentNullException(nameof(name));

ListBuilder<PropertyInfo> candidates = GetPropertyCandidates(name, bindingAttr, types, false);

Expand DownExpand Up@@ -2788,7 +2788,7 @@ public override InterfaceMapping GetInterfaceMap(Type ifaceType)

public override EventInfo? GetEvent(string name, BindingFlags bindingAttr)
{
if (name is null) throw new ArgumentNullException();
if (name is null) throw new ArgumentNullException(nameof(name));

FilterHelper(bindingAttr, ref name, out _, out MemberListType listType);

Expand All@@ -2814,7 +2814,7 @@ public override InterfaceMapping GetInterfaceMap(Type ifaceType)

public override FieldInfo? GetField(string name, BindingFlags bindingAttr)
{
if (name is null) throw new ArgumentNullException();
if (name is null) throw new ArgumentNullException(nameof(name));

FilterHelper(bindingAttr, ref name, out _, out MemberListType listType);

Expand DownExpand Up@@ -2851,7 +2851,7 @@ public override InterfaceMapping GetInterfaceMap(Type ifaceType)

public override Type? GetInterface(string fullname, bool ignoreCase)
{
if (fullname is null) throw new ArgumentNullException();
if (fullname is null) throw new ArgumentNullException(nameof(fullname));

BindingFlags bindingAttr = BindingFlags.Public | BindingFlags.NonPublic;

Expand DownExpand Up@@ -2885,7 +2885,7 @@ public override InterfaceMapping GetInterfaceMap(Type ifaceType)

public override Type? GetNestedType(string fullname, BindingFlags bindingAttr)
{
if (fullname is null) throw new ArgumentNullException();
if (fullname is null) throw new ArgumentNullException(nameof(fullname));

bindingAttr &= ~BindingFlags.Static;
string name, ns;
Expand DownExpand Up@@ -2913,7 +2913,7 @@ public override InterfaceMapping GetInterfaceMap(Type ifaceType)

public override MemberInfo[] GetMember(string name, MemberTypes type, BindingFlags bindingAttr)
{
if (name is null) throw new ArgumentNullException();
if (name is null) throw new ArgumentNullException(nameof(name));

ListBuilder<MethodInfo> methods = default;
ListBuilder<ConstructorInfo> constructors = default;
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -287,7 +287,7 @@ bool compressStack
}
else
{
Comment thread
buyaa-n marked this conversation as resolved.
throw new ArgumentNullException(nameof(WaitOrTimerCallback));
throw new ArgumentNullException(nameof(callBack));
}
return registeredWaitHandle;
}
Expand Down
4 changes: 2 additions & 2 deletions src/libraries/Common/src/System/Threading/Tasks/TaskToApm.cs
Original file line numberDiff line numberDiff line change
Expand Up@@ -43,7 +43,7 @@ public static void End(IAsyncResult asyncResult)
return;
}

throw new ArgumentNullException();
throw new ArgumentNullException(nameof(asyncResult));
}

/// <summary>Processes an IAsyncResult returned by Begin.</summary>
Expand All@@ -55,7 +55,7 @@ public static TResult End<TResult>(IAsyncResult asyncResult)
return task.GetAwaiter().GetResult();
}

throw new ArgumentNullException();
throw new ArgumentNullException(nameof(asyncResult));
}

/// <summary>Provides a simple IAsyncResult that wraps a Task.</summary>
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -32,12 +32,12 @@ internal DiagnosticCounter(string name, EventSource eventSource)
{
if (name == null)
{
throw new ArgumentNullException(nameof(Name));
throw new ArgumentNullException(nameof(name));
}

if (eventSource == null)
{
throw new ArgumentNullException(nameof(EventSource));
throw new ArgumentNullException(nameof(eventSource));
}

Name = name;
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -262,7 +262,7 @@ private void Write<T>(EventSource eventSource, string? eventName, ref EventSourc
if (this.state != State.Started)
throw new InvalidOperationException(); // Write after stop.
if (eventName == null)
throw new ArgumentNullException();
throw new ArgumentNullException(nameof(eventName));

eventSource.Write(eventName, ref options, ref this.activityId, ref s_empty, ref data);
}
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -813,7 +813,7 @@ private static int AddValueToMetaData(List<byte> metaData, string value)
{
if (!(i + 1 < value.Length))
{
throw new ArgumentException(SR.EventSource_EvenHexDigits, "traits");
throw new ArgumentException(SR.EventSource_EvenHexDigits, nameof(value));
}
metaData.Add((byte)(HexDigit(value[i]) * 16 + HexDigit(value[i + 1])));
i++;
Expand All@@ -826,7 +826,7 @@ private static int AddValueToMetaData(List<byte> metaData, string value)
}
else
{
throw new ArgumentException(SR.Format(SR.EventSource_IllegalValue, value), "traits");
throw new ArgumentException(SR.Format(SR.EventSource_IllegalValue, value), nameof(value));
}

return metaData.Count - startPos;
Expand All@@ -850,7 +850,7 @@ private static int HexDigit(char c)
return c - 'A' + 10;
}

throw new ArgumentException(SR.Format(SR.EventSource_BadHexDigit, c), "traits");
throw new ArgumentException(SR.Format(SR.EventSource_BadHexDigit, c), nameof(c));
}

private NameInfo? UpdateDescriptor(
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -394,7 +394,7 @@ public virtual unsafe void Write(string value)
{
if (charStart < 0 || charCount < 0 || charStart > value.Length - charCount)
{
throw new ArgumentOutOfRangeException(nameof(charCount));
throw new ArgumentOutOfRangeException(nameof(value));
}
fixed (char* pChars = value)
{
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -415,7 +415,7 @@ public unsafe byte* PositionPointer
throw new IOException(SR.IO_SeekBeforeBegin);
long newPosition = (long)value - (long)_mem;
if (newPosition < 0)
throw new ArgumentOutOfRangeException("offset", SR.ArgumentOutOfRange_UnmanagedMemStreamLength);
throw new ArgumentOutOfRangeException(nameof(value), SR.ArgumentOutOfRange_UnmanagedMemStreamLength);

Interlocked.Exchange(ref _position, newPosition);
}
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -63,7 +63,7 @@ public static string ComputeDisplayName(string? name, Version? version, string?
if (pkt != null)
{
if (pkt.Length > PUBLIC_KEY_TOKEN_LEN)
throw new ArgumentException();
throw new ArgumentException(null, nameof(pkt));

sb.Append(", PublicKeyToken=");
if (pkt.Length == 0)
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -97,7 +97,7 @@ internal static unsafe int GetAnsiStringByteCount(ReadOnlySpan<char> chars)
byteLength = Interop.Kernel32.WideCharToMultiByte(
Interop.Kernel32.CP_ACP, Interop.Kernel32.WC_NO_BEST_FIT_CHARS, pChars, chars.Length, null, 0, IntPtr.Zero, IntPtr.Zero);
if (byteLength <= 0)
throw new ArgumentException();
throw new ArgumentException(null, nameof(chars));
}
}

Expand All@@ -121,7 +121,7 @@ internal static unsafe void GetAnsiStringBytes(ReadOnlySpan<char> chars, Span<by
byteLength = Interop.Kernel32.WideCharToMultiByte(
Interop.Kernel32.CP_ACP, Interop.Kernel32.WC_NO_BEST_FIT_CHARS, pChars, chars.Length, pBytes, bytes.Length, IntPtr.Zero, IntPtr.Zero);
if (byteLength <= 0)
throw new ArgumentException();
throw new ArgumentException(null, nameof(bytes));
}
}

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -109,7 +109,7 @@ internal EncoderFallbackException(
}
if (!char.IsLowSurrogate(charUnknownLow))
{
throw new ArgumentOutOfRangeException(nameof(CharUnknownLow),
throw new ArgumentOutOfRangeException(nameof(charUnknownLow),
SR.Format(SR.ArgumentOutOfRange_Range, 0xDC00, 0xDFFF));
}

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -961,7 +961,7 @@ private StringBuilder AppendCore(StringBuilder value, int startIndex, int count)

if ((uint)newLength > (uint)m_MaxCapacity)
{
throw new ArgumentOutOfRangeException(nameof(Capacity), SR.ArgumentOutOfRange_Capacity);
throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_Capacity);
}

while (count > 0)
Expand DownExpand Up@@ -1144,7 +1144,9 @@ public StringBuilder Remove(int startIndex, int length)
return this;
}

#pragma warning disable CA1830 // Prefer strongly-typed Append and Insert method overloads on StringBuilder.
public StringBuilder Append(bool value) => Append(value.ToString());
#pragma warning restore CA1830 // Prefer strongly-typed Append and Insert method overloads on StringBuilder.

public StringBuilder Append(char value)
{
Expand DownExpand Up@@ -2401,7 +2403,7 @@ private void ExpandByABlock(int minBlockCharCount)

if ((minBlockCharCount + Length) > m_MaxCapacity || minBlockCharCount + Length < minBlockCharCount)
{
throw new ArgumentOutOfRangeException("requiredLength", SR.ArgumentOutOfRange_SmallCapacity);
throw new ArgumentOutOfRangeException(nameof(minBlockCharCount), SR.ArgumentOutOfRange_SmallCapacity);
}

// - We always need to make the new chunk at least as big as was requested (`minBlockCharCount`).
Expand DownExpand Up@@ -2490,7 +2492,7 @@ private void MakeRoom(int index, int count, out StringBuilder chunk, out int ind

if (count + Length > m_MaxCapacity || count + Length < count)
{
throw new ArgumentOutOfRangeException("requiredLength", SR.ArgumentOutOfRange_SmallCapacity);
throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_SmallCapacity);
}

chunk = this;
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -243,7 +243,7 @@ public bool TrySetApartmentState(ApartmentState state)
break;

default:
throw new ArgumentOutOfRangeException(SR.ArgumentOutOfRange_Enum, nameof(state));
throw new ArgumentOutOfRangeException(nameof(state), SR.ArgumentOutOfRange_Enum);
}

return TrySetApartmentStateUnchecked(state);
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -165,7 +165,7 @@ public void GetRuntimeEvent()
});


Assert.Throws<ArgumentNullException>(null, () =>
Assert.Throws<ArgumentNullException>("name", () =>
{
typeof(RuntimeReflectionExtensionsTests).GetRuntimeEvent(null);
});
Expand DownExpand Up@@ -250,7 +250,7 @@ public void GetRuntimeField()
});


Assert.Throws<ArgumentNullException>(null, () =>
Assert.Throws<ArgumentNullException>("name", () =>
{
typeof(RuntimeReflectionExtensionsTests).GetRuntimeField(null);
});
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -40,7 +40,7 @@ public void Ctor_NullType_ThrowsNullReferenceException()
[Fact]
public void Ctor_NullEventName_ThrowsArgumentNullException()
{
AssertExtensions.Throws<ArgumentNullException>(null, () => new ComAwareEventInfo(typeof(NonComObject), null));
AssertExtensions.Throws<ArgumentNullException>("name", () => new ComAwareEventInfo(typeof(NonComObject), null));
}

[Fact]
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -186,8 +186,8 @@ public void OffsetOf_NullType_ThrowsArgumentNullException()
[Fact]
public void OffsetOf_NullFieldName_ThrowsArgumentNullException()
{
AssertExtensions.Throws<ArgumentNullException>(null, () => Marshal.OffsetOf(new object().GetType(), null));
AssertExtensions.Throws<ArgumentNullException>(null, () => Marshal.OffsetOf<object>(null));
AssertExtensions.Throws<ArgumentNullException>("name", () => Marshal.OffsetOf(new object().GetType(), null));
AssertExtensions.Throws<ArgumentNullException>("name", () => Marshal.OffsetOf<object>(null));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If Marshal.OffsetOf were a more entry-level method, I'd advocate taking a change for it to validate the field name directly so it could throw the ANE with the correct parameter name ("fieldName"). But I'm guessing our position right now is "it's an advanced enough API that the caller is expected to realize the parameter sharing between OffsetOf's fieldName and GetField's name."

Writing this down in case someone else is iffy about it and wants to have the discussion. But currently sighing and not recommending further action.

}

[Fact]
Expand Down
Loading