diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/DefaultCharset.java b/core/src/main/java/com/google/errorprone/bugpatterns/DefaultCharset.java index 48b7668f0264..e3640904b5e2 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/DefaultCharset.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/DefaultCharset.java @@ -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()); } @@ -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()); } diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/DefaultCharsetTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/DefaultCharsetTest.java index 2e58bae3f258..059e8271b2c2 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/DefaultCharsetTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/DefaultCharsetTest.java @@ -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(); @@ -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();