-
Notifications
You must be signed in to change notification settings - Fork 392
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
[#4209] chore replace hardcoded value with std definition #6354
Conversation
return new String(bb.array(), bb.arrayOffset() + bb.position(), bb.remaining(), "UTF-8"); | ||
} catch (UnsupportedEncodingException e) { | ||
throw new IllegalCharsetNameException("UTF-8"); // won't happen. | ||
} |
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.
Why did you remove this code?
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.
Why did you remove this code?
The String constructor used here does not declare that it throws an UnsupportedEncodingException
because StandardCharsets.UTF_8
guarantees that the encoding is supported. However, an IndexOutOfBoundsException
could occur in this context.
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.
That seems Ok, but I assume it was there for some reason for it originally, so it may not be best to remove it.
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.
That seems Ok, but I assume it was there for some reason for it originally, so it may not be best to remove it.
we can't do that, if we use:
try {
return new String(bb.array(), bb.arrayOffset() + bb.position(), bb.remaining(), StandardCharsets.UTF_8);
} catch (UnsupportedEncodingException e) {
throw new IllegalCharsetNameException("UTF-8"); // won't happen.
}
the complier will report Exception java.io.UnsupportedEncodingException is never thrown in the corresponding try block like this:
maybe we can use Exception
replace UnsupportedEncodingException
?
We use Spotless to ensure our code is consistently formatted. You'll need to run |
Can you please update the PR description like other PRs? |
yes |
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.
LGTM thanks for the improvement
What changes were proposed in this pull request?
Use standard definition lib value to replace the hardcoded value: UTF-8.
Why are the changes needed?
Fix: #4209
Does this PR introduce any user-facing change?
no
How was this patch tested?
no