diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/EagerStringFormatting.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/EagerStringFormatting.java index 2e2756f024..036bdb7056 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/EagerStringFormatting.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/EagerStringFormatting.java @@ -43,8 +43,7 @@ import tech.picnic.errorprone.utils.SourceCode; /** - * A {@link BugChecker} that flags {@link String#format(String, Object...)}, {@link - * String#format(Locale, String, Object...)} and {@link String#formatted(Object...)} invocations + * A {@link BugChecker} that flags {@link String#format} and {@link String#formatted} invocations * that can be omitted by delegating to another format method. */ // XXX: The special-casing of Throwable applies only to SLF4J 1.6.0+; see @@ -53,6 +52,9 @@ // `RedundantStringConversion` checks. Look into deduplicating them. // XXX: Should we also simplify e.g. `LOG.error(String.join("sep", arg1, arg2), throwable)`? Perhaps // that's too obscure. +// XXX: This check currently only flags string format expressions that are a direct argument to +// another format-capable method invocation. Indirect cases, such as where the result is assigned to +// a variable, are currently not covered. @AutoService(BugChecker.class) @BugPattern( summary = "String formatting can be deferred", diff --git a/error-prone-utils/src/main/java/tech/picnic/errorprone/utils/SourceCode.java b/error-prone-utils/src/main/java/tech/picnic/errorprone/utils/SourceCode.java index 741a50a644..5266385a2f 100644 --- a/error-prone-utils/src/main/java/tech/picnic/errorprone/utils/SourceCode.java +++ b/error-prone-utils/src/main/java/tech/picnic/errorprone/utils/SourceCode.java @@ -63,9 +63,11 @@ public static String treeToString(Tree tree, VisitorState state) { * found. * @return A non-{@code null} string. * @apiNote This method differs from {@link com.sun.tools.javac.util.Constants#format(Object)} in - * that it does not superfluously escape single quote characters. It is different from {@link + * that it does not superfluously escape single quote characters (the latter only does the + * "clean thing" starting from JDK 23). It is different from {@link * VisitorState#getConstantExpression(Object)} in that it is more performant and accepts any * {@link CharSequence} instance. + * @see JDK-8325078 */ // XXX: Drop this method if https://github.com/google/error-prone/pull/4586 is merged and released // with the proposed `CharSequence` compatibility change.