From cf13110aa34d6dfc0a588eeb4b91af626897be21 Mon Sep 17 00:00:00 2001 From: James Ko Date: Mon, 4 Jul 2016 20:16:44 -0400 Subject: [PATCH] Fix CoreFX test failures Commit migrated from https://github.com/dotnet/coreclr/commit/4fd1bfef80fbd4ccb7625196cd841f4fa6415282 --- .../src/mscorlib/src/System/Text/ASCIIEncoding.cs | 5 ----- .../src/mscorlib/src/System/Text/EncodingForwarder.cs | 16 ++++++++++++---- src/coreclr/src/mscorlib/src/System/Text/UTF8Encoding.cs | 2 -- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/coreclr/src/mscorlib/src/System/Text/ASCIIEncoding.cs b/src/coreclr/src/mscorlib/src/System/Text/ASCIIEncoding.cs index bf94b81..4e2b798 100644 --- a/src/coreclr/src/mscorlib/src/System/Text/ASCIIEncoding.cs +++ b/src/coreclr/src/mscorlib/src/System/Text/ASCIIEncoding.cs @@ -66,8 +66,6 @@ namespace System.Text [System.Security.SecuritySafeCritical] // auto-generated public override int GetByteCount(String chars) { - // NOTE: If chars is null, this will throw an ArgumentNullException - // with the parameter name "s" rather than "chars" return EncodingForwarder.GetByteCount(this, chars); } @@ -83,7 +81,6 @@ namespace System.Text public override int GetBytes(String chars, int charIndex, int charCount, byte[] bytes, int byteIndex) { - // NOTE: Will throw ArgumentNull of "s" is chars is null. return EncodingForwarder.GetBytes(this, chars, charIndex, charCount, bytes, byteIndex); } @@ -149,8 +146,6 @@ namespace System.Text [System.Security.SecuritySafeCritical] // auto-generated public override String GetString(byte[] bytes, int byteIndex, int byteCount) { - // NOTE: If the byteIndex/byteCount parameters are invalid, this will - // throw an ArgumentOutOfRange for "index" or "count" instead of those names. return EncodingForwarder.GetString(this, bytes, byteIndex, byteCount); } diff --git a/src/coreclr/src/mscorlib/src/System/Text/EncodingForwarder.cs b/src/coreclr/src/mscorlib/src/System/Text/EncodingForwarder.cs index 51c4830..abf21d8 100644 --- a/src/coreclr/src/mscorlib/src/System/Text/EncodingForwarder.cs +++ b/src/coreclr/src/mscorlib/src/System/Text/EncodingForwarder.cs @@ -63,7 +63,8 @@ namespace System.Text Contract.Assert(encoding != null); if (s == null) { - throw new ArgumentNullException("s"); + string paramName = encoding is ASCIIEncoding ? "chars" : "s"; // ASCIIEncoding calls the string chars + throw new ArgumentNullException(paramName); } Contract.EndContractBlock(); @@ -101,7 +102,8 @@ namespace System.Text Contract.Assert(encoding != null); if (s == null || bytes == null) { - throw new ArgumentNullException(s == null ? "s" : "bytes", Environment.GetResourceString("ArgumentNull_Array")); + string stringName = encoding is ASCIIEncoding ? "chars" : "s"; // ASCIIEncoding calls the first parameter chars + throw new ArgumentNullException(s == null ? stringName : "bytes", Environment.GetResourceString("ArgumentNull_Array")); } if (charIndex < 0 || charCount < 0) { @@ -109,7 +111,9 @@ namespace System.Text } if (s.Length - charIndex < charCount) { - throw new ArgumentOutOfRangeException("s", Environment.GetResourceString("ArgumentOutOfRange_IndexCount")); + string stringName = encoding is ASCIIEncoding ? "chars" : "s"; // ASCIIEncoding calls the first parameter chars + // Duplicate the above check since we don't want the overhead of a type check on the general path + throw new ArgumentOutOfRangeException(stringName, Environment.GetResourceString("ArgumentOutOfRange_IndexCount")); } if (byteIndex < 0 || byteIndex > bytes.Length) { @@ -293,7 +297,11 @@ namespace System.Text } if (index < 0 || count < 0) { - throw new ArgumentOutOfRangeException(index < 0 ? "index" : "count", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); + // ASCIIEncoding has different names for its parameters here (byteIndex, byteCount) + bool ascii = encoding is ASCIIEncoding; + string indexName = ascii ? "byteIndex" : "index"; + string countName = ascii ? "byteCount" : "count"; + throw new ArgumentOutOfRangeException(index < 0 ? indexName : countName, Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum")); } if (bytes.Length - index < count) { diff --git a/src/coreclr/src/mscorlib/src/System/Text/UTF8Encoding.cs b/src/coreclr/src/mscorlib/src/System/Text/UTF8Encoding.cs index e21f1cb..fa6e957 100644 --- a/src/coreclr/src/mscorlib/src/System/Text/UTF8Encoding.cs +++ b/src/coreclr/src/mscorlib/src/System/Text/UTF8Encoding.cs @@ -124,8 +124,6 @@ namespace System.Text [System.Security.SecuritySafeCritical] // auto-generated public override int GetByteCount(String chars) { - // NOTE: If chars is null, this will throw an ArgumentNullException - // with the parameter name "s" rather than "chars" return EncodingForwarder.GetByteCount(this, chars); } -- 2.7.4