-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reintroduce an Exception type for invalid UTF-8 #10553
Conversation
Introduce `Utf8StringBuilder.InvalidUtf8Exception` as a substitute for the removed `Utf8Appendable.NotUtf8Exception`.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we get by with a nested cause instead of reintroducing the top level exception?
@@ -329,7 +329,7 @@ private static void decodeUtf8To(String query, int offset, int length, BiConsume | |||
switch (c) | |||
{ | |||
case '&': | |||
value = buffer.takeCompleteString(() -> new IllegalArgumentException("Invalid value: Bad UTF-8")); | |||
value = buffer.takeCompleteString(() -> new Utf8StringBuilder.InvalidUtf8Exception("Invalid value: Bad UTF-8")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer something like this instead ...
value = buffer.takeCompleteString(() -> new IllegalArgumentException(
new CharacterCodingException("Invalid value: Bad UTF-8")));
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem is that CharacterCodingException
does not take a message. It doesn't even take a cause, so we really have to extend it and force the toString and message, otherwise we don't know what the character coding problem is.
So now I have:
public static class Utf8CharacterCodingException extends CharacterCodingException
{
@Override
public String getMessage()
{
return "Invalid UTF-8";
}
@Override
public String toString()
{
return "%s@%x: Invalid UTF-8".formatted(CharacterCodingException.class.getSimpleName(), hashCode());
}
}
public static class Utf8IllegalArgumentException extends IllegalArgumentException
{
public Utf8IllegalArgumentException()
{
super(new Utf8CharacterCodingException());
}
}
So any exception will always have a CharacterCodingException
in its causal chain. It will also have the "Invalid ITF-8" message reported.
Almost feels like we should use Like the JDK itself does in the |
Introduce
Utf8StringBuilder.InvalidUtf8Exception
as a substitute for the removedUtf8Appendable.NotUtf8Exception
.