Skip to content

Commit

Permalink
Update DefaultCharset.java
Browse files Browse the repository at this point in the history
Prefer (?, Charset) to (?, String) constructor

Such as https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/util/Scanner.html#%3Cinit%3E(java.io.File,java.nio.charset.Charset)

Fixes #4114

FUTURE_COPYBARA_INTEGRATE_REVIEW=#4114 from delanym:patch-1 18dbdc4
PiperOrigin-RevId: 568045902
  • Loading branch information
delanym authored and Error Prone Team committed Sep 25, 2023
1 parent 25e5c1d commit 273a77e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ private Description handleScanner(NewClassTree tree) {
SuggestedFix.builder()
.postfixWith(
getOnlyElement(tree.getArguments()),
String.format(", %s.name()", charsetFix.replacement()));
String.format(", %s", charsetFix.replacement()));
charsetFix.addImport(fix);
description.addFix(fix.build());
}
Expand Down Expand Up @@ -544,7 +544,7 @@ private Description handlePrintWriter(NewClassTree tree) {
SuggestedFix.builder()
.postfixWith(
getOnlyElement(tree.getArguments()),
String.format(", %s.name()", charsetFix.replacement()));
String.format(", %s", charsetFix.replacement()));
charsetFix.addImport(fix);
description.addFix(fix.build());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -389,8 +389,8 @@ public void printWriter() {
" new BufferedWriter(new OutputStreamWriter(System.err, UTF_8)), true);",
" PrintWriter pw2 = new PrintWriter(",
" new BufferedWriter(new OutputStreamWriter(System.err, UTF_8)));",
" PrintWriter pw3 = new PrintWriter(\"test\", UTF_8.name());",
" PrintWriter pw4 = new PrintWriter(new File(\"test\"), UTF_8.name());",
" PrintWriter pw3 = new PrintWriter(\"test\", UTF_8);",
" PrintWriter pw4 = new PrintWriter(new File(\"test\"), UTF_8);",
" }",
"}")
.doTest();
Expand Down Expand Up @@ -494,10 +494,10 @@ public void scannerDefaultCharset() {
"import java.util.Scanner;",
"class Test {",
" void f() throws Exception {",
" new Scanner((InputStream) null, UTF_8.name());",
" new Scanner((File) null, UTF_8.name());",
" new Scanner((Path) null, UTF_8.name());",
" new Scanner((ReadableByteChannel) null, UTF_8.name());",
" new Scanner((InputStream) null, UTF_8);",
" new Scanner((File) null, UTF_8);",
" new Scanner((Path) null, UTF_8);",
" new Scanner((ReadableByteChannel) null, UTF_8);",
" }",
"}")
.doTest();
Expand Down

0 comments on commit 273a77e

Please sign in to comment.