From cff002daf48a0a1de047be1865495734f9eb1403 Mon Sep 17 00:00:00 2001 From: Kurt Alfred Kluever Date: Thu, 13 Aug 2026 13:32:21 -0700 Subject: [PATCH] Add a terrible test for InlineMeSuggester in anonymous classes. InlineMeSuggester currently suggests adding @InlineMe to @Deprecated methods inside anonymous classes that override an interface method. Such methods have no external callers to migrate and should not receive an @InlineMe suggestion. Add a unit test in SuggesterTest that asserts the current behavior with a TODO pointing to issue #5844 (in the spirit of[] PiperOrigin-RevId: 964263575 --- .../bugpatterns/inlineme/SuggesterTest.java | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/inlineme/SuggesterTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/inlineme/SuggesterTest.java index 3a3b591daec..4783bcc8b18 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/inlineme/SuggesterTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/inlineme/SuggesterTest.java @@ -1394,4 +1394,55 @@ public static String getString(byte[] bytes, int offset, int length) { """) .doTest(); } + + @Test + public void anonymousClassOverride() { + refactoringTestHelper + .addInputLines( + "Client.java", + """ + package com.google.frobber; + + public final class Client { + interface Handler { + String handle(); + } + + void toto() { + new Handler() { + @Deprecated + public String handle() { + return "handled"; + } + }.handle(); + } + } + """) + // TODO(user): this is a bug; should + // expectUnchanged() + .addOutputLines( + "Client.java", + """ + package com.google.frobber; + + import com.google.errorprone.annotations.InlineMe; + + public final class Client { + interface Handler { + String handle(); + } + + void toto() { + new Handler() { + @InlineMe(replacement = "\\"handled\\"") + @Deprecated + public String handle() { + return "handled"; + } + }.handle(); + } + } + """) + .doTest(); + } }