Skip to content

Commit 073cb54

Browse files
committed
Use FormatException instead of ParseException
1 parent b64e5df commit 073cb54

2 files changed

Lines changed: 6 additions & 7 deletions

File tree

src/Lucene.Net.Tests/Util/TestUnicodeUtil.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ public void TestUTF8toUTF16Exception(byte[] invalidUtf8, bool shouldThrow)
339339

340340
if (shouldThrow)
341341
{
342-
Assert.Throws<ParseException>(() => UnicodeUtil.UTF8toUTF16(invalidUtf8, scratch));
342+
Assert.Throws<FormatException>(() => UnicodeUtil.UTF8toUTF16(invalidUtf8, scratch));
343343
}
344344
else
345345
{

src/Lucene.Net/Util/UnicodeUtil.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using J2N;
22
using J2N.Text;
33
using Lucene.Net.Diagnostics;
4-
using Lucene.Net.Support;
54
using System;
65
using System.Diagnostics.CodeAnalysis;
76
using System.Runtime.CompilerServices;
@@ -887,7 +886,7 @@ public static string ToHexString(string s)
887886
/// it doesn't provide enough space to hold the worst case of each byte becoming a UTF-16 codepoint.
888887
/// <para/>
889888
/// NOTE: Full characters are read, even if this reads past the length passed (and
890-
/// can result in an <see cref="IndexOutOfRangeException"/> if invalid UTF-8 is passed).
889+
/// can result in an <see cref="FormatException"/> if invalid UTF-8 is passed).
891890
/// Explicit checks for valid UTF-8 are not performed.
892891
/// </summary>
893892
/// <seealso cref="UTF8toUTF16(ReadOnlySpan{byte}, CharsRef)"/>
@@ -902,7 +901,7 @@ public static void UTF8toUTF16(byte[] utf8, int offset, int length, CharsRef cha
902901
/// it doesn't provide enough space to hold the worst case of each byte becoming a UTF-16 codepoint.
903902
/// <para/>
904903
/// NOTE: Full characters are read, even if this reads past the length passed (and
905-
/// can result in an <see cref="IndexOutOfRangeException"/> if invalid UTF-8 is passed).
904+
/// can result in an <see cref="FormatException"/> if invalid UTF-8 is passed).
906905
/// Explicit checks for valid UTF-8 are not performed.
907906
/// </summary>
908907
/// <remarks>
@@ -927,15 +926,15 @@ public static void UTF8toUTF16(ReadOnlySpan<byte> utf8, CharsRef chars)
927926
{
928927
if (utf8.Length <= i)
929928
{
930-
throw new ParseException($"Invalid UTF-8 starting at [{b:x2}] at offset {i - 1}", i - 1);
929+
throw new FormatException($"Invalid UTF-8 starting at [{b:x2}] at offset {i - 1}");
931930
}
932931
@out[out_offset++] = (char)(((b & 0x1f) << 6) + (utf8[i++] & 0x3f));
933932
}
934933
else if (b < 0xf0)
935934
{
936935
if (utf8.Length <= i + 1)
937936
{
938-
throw new ParseException($"Invalid UTF-8 starting at [{b:x2}] at offset {i - 1}", i - 1);
937+
throw new FormatException($"Invalid UTF-8 starting at [{b:x2}] at offset {i - 1}");
939938
}
940939
@out[out_offset++] = (char)(((b & 0xf) << 12) + ((utf8[i] & 0x3f) << 6) + (utf8[i + 1] & 0x3f));
941940
i += 2;
@@ -944,7 +943,7 @@ public static void UTF8toUTF16(ReadOnlySpan<byte> utf8, CharsRef chars)
944943
{
945944
if (utf8.Length <= i + 2)
946945
{
947-
throw new ParseException($"Invalid UTF-8 starting at [{b:x2}] at offset {i - 1}", i - 1);
946+
throw new FormatException($"Invalid UTF-8 starting at [{b:x2}] at offset {i - 1}");
948947
}
949948
if (Debugging.AssertsEnabled) Debugging.Assert(b < 0xf8, "b = 0x{0:x}", b);
950949
int ch = ((b & 0x7) << 18) + ((utf8[i] & 0x3f) << 12) + ((utf8[i + 1] & 0x3f) << 6) + (utf8[i + 2] & 0x3f);

0 commit comments

Comments
 (0)