Conversation
The builder seeded its CharsetEncoder from the default Charset and threw IllegalStateException when the Charset and the encoder disagreed, so both setCharset and setCharsetEncoder failed for anything but the platform default. Keep the pair consistent the way ReaderInputStream.Builder does: setCharset refreshes the encoder and setCharsetEncoder sets the Charset. The mismatch guard has nothing left to catch and is removed. The class Javadoc's Charset example passed a Charset to setCharsetEncoder, which does not compile; it now calls setCharset.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
FileWriterWithEncoding.Builderseeds its encoder from the default Charset, andgetEncoder()throwsIllegalStateExceptionwhen Charset and encoder disagree. SosetCharset(UTF_16)throws atget(), andsetCharsetEncoder(UTF_16.newEncoder())throws too, because the other half is still the default: the builder could not write any encoding but the platform default. The class Javadoc's Charset example also passes aCharsettosetCharsetEncoder, which does not compile.The builder now keeps the pair consistent as
ReaderInputStream.Builderdoes:setCharsetrefreshes the encoder,setCharsetEncodersets the Charset, and the mismatch guard, with nothing left to catch, is removed. The example callssetCharset.Tests:
testBuilder_nonDefaultCharsetandtestBuilder_nonDefaultCharsetEncoder, red on master and green with the change. Default Maven goal green.mvn; that'smvnon the command line by itself.