Repository navigation
Conversation
Blank lines between the steps of format() and processArgs(), var for the entry of the result loop and for the cause of a failed format, a static import of ofNullable, a pattern-matching instanceof for the FormatterException, and Files.writeString in place of getBytes(UTF_8), which writes the same bytes. The continue after a failed write goes: nothing in the loop body came after it, as Error Prone's RedundantControlFlow pointed out.
new String(bytes, UTF_8) turned each byte that is not UTF-8 into U+FFFD, and --replace wrote the result back: an "é" saved as Latin-1 became EF BF BD, and the exit code was 0. Files.readString throws on such a byte, so the file is reported as one Main could not read and stays as it is, with exit code 2. Standard input still decodes with replacement.
Only Main.main and the tests of the package call them. Code outside the package that runs the command line in process, through new Main(out, err, in).format(args), no longer compiles; nothing in this repository, the Maven plugin or the GitHub Action does that.
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.
Readability changes to
Main, and two changes that come with them, each in a commit of its own so that either can be dropped.format()andprocessArgs(),varfor the entry of the result loop and the cause of a failed format, a static import ofofNullable, a pattern-matchinginstanceoffor theFormatterException, andFiles.writeString, which writes the same bytes asgetBytes(UTF_8). Thecontinueafter a failed write goes: it was the last statement of the loop body (Error Prone'sRedundantControlFlow).Files.readStringreplacesnew String(Files.readAllBytes(path), UTF_8), which turned each byte that is not UTF-8 into U+FFFD.Main.formatandMain.processArgsbecome package-private. OnlyMain.mainand the tests of the package call them.What changes for users
--replaceon a file saved as Latin-1, withéin a comment: 21.0.2 writes the file back withEF BF BDin place of theéand exits with 0. Now Main prints<file>: could not read file: Input length = 3, leaves the file as it is and exits with 2. Standard input still decodes with replacement.new Main(out, err, in).format(args)no longer compiles. Nothing in this repository, the Maven plugin or the GitHub Action does.Tests
On JDK 21,
:open-java-format:checkpasses on each of the three commits, with no new warning inMain; 1,422 tests.