Skip to content
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

[charset] Use charset for name to avoid potential internal exception #923

Merged
merged 1 commit into from
Jul 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/main/java/net/revelc/code/formatter/FormatterMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -880,7 +880,7 @@ private String sha512hash(final String str) {
private String readFileAsString(final File file) throws IOException {
final var fileData = new StringBuilder(1000);
try (var fileStream = Files.newInputStream(file.toPath());
var fileReader = new InputStreamReader(fileStream, this.encoding);
var fileReader = new InputStreamReader(fileStream, Charset.forName(this.encoding));
var reader = new BufferedReader(fileReader)) {
var buf = new char[1024];
var numRead = 0;
Expand Down Expand Up @@ -910,7 +910,7 @@ private void writeStringToFile(final String str, final File file) throws IOExcep
}

try (var fileStream = Files.newOutputStream(file.toPath());
var fileWriter = new OutputStreamWriter(fileStream, this.encoding);
var fileWriter = new OutputStreamWriter(fileStream, Charset.forName(this.encoding));
var bw = new BufferedWriter(fileWriter)) {
bw.write(str);
}
Expand Down