From f9acde6ccec9161bd89c38a346ad857c7fc76ad6 Mon Sep 17 00:00:00 2001 From: Stephan Schroevers Date: Sat, 3 Dec 2022 09:25:44 +0100 Subject: [PATCH] Another gotcha --- .../picnic/errorprone/bugpatterns/ImplicitLocaleUsage.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/ImplicitLocaleUsage.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/ImplicitLocaleUsage.java index 1af47c3a22..05f6d8823f 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/ImplicitLocaleUsage.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/ImplicitLocaleUsage.java @@ -58,6 +58,10 @@ public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState } private static Fix suggestLocale(MethodInvocationTree tree, String locale, VisitorState state) { + // XXX: The logic that replaces the first parenthesis assumes that `tree` does not have a source + // code representation such as `str.toLowerCase/* Some comment with parens (). */()`. In such a + // case the comment, rather than the method invocation arguments, will be modified. Implement a + // generic solution for this. return SuggestedFix.builder() .addImport("java.util.Locale") .replace(tree, SourceCode.treeToString(tree, state).replaceFirst("\\(", '(' + locale))