Use Charset instead of String for Protocol#CHARSET
#2658
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This replaces the type of
Protocol#CHARSETwithCharsettype which is less error-prone to use and initializes it with a constant fromStandardCharsets.This also updates all (2) usages which relied on
Stringbeing used (i.e.try-catchare removed as they were catchingUnsupportedEncodingException).Motivation
Using
Charsetinstead of raw string allows less error-prone code and allows to omit unneededUnsupportedEncodingExceptioncatching.Problems
This is technically a breaking change as API users relying on this field type being of type
Stringmay have the following incompatibilities:source: if someone used the
Stringvalue such as by usingCharset.forName(Protocol.CHARSET)than this calls will no longer compilerbinary: if the compiler used by them failed to inline the constant (although it had to) then
getstaticmay fail, although it is very unlikely as the inlining compiler behaviour is specifiedHowever, as the next version (4.0.0) is going to be a major release, such impact is SemVer-compatible and its impact is not that serious and old code can be easily refactored.
Alternatives
to hold the
Charset-typed object, but it is counterintiutive and leads to dependency on legacy / not-that-good API design flaws.Stringfield