Skip to content

InlineMeSuggester: false positive on an anonymous-class override merely annotated @Deprecated #5844

@Chordrain

Description

@Chordrain

Error Prone version

Error Prone 2.49.0 (javac 21.0.8, --source/--target 21)

Check name

InlineMeSuggester

Description

InlineMeSuggester suggests adding @InlineMe to a @Deprecated method that has a clear inline replacement, so callers can be migrated automatically. It fires on a method that overrides an interface method inside an anonymous class and whose body is just return "handled";. Such a method has no external callers to migrate (it is reached only through the interface) and no delegating replacement to inline, so suggesting @InlineMe is not actionable. The only difference from the non-firing version is that its annotation is @Deprecated instead of @Override, which suggests the check keys on the presence of @Deprecated without gating on whether the method is an override or has an inlineable replacement.

Reproducer

// BEFORE — no finding (@Override)
public class Sample {
  interface Handler { String handle(); }
  class A {
    void toto() {
      new Handler() {
        @Override
        public String handle() { return "handled"; }
      }.handle();
    }
  }
}
// AFTER — InlineMeSuggester fires on handle() (@Deprecated)
public class Sample {
  interface Handler { String handle(); }
  class A {
    void toto() {
      new Handler() {
        @Deprecated
        public String handle() { return "handled"; }
      }.handle();
    }
  }
}

Expected behavior

No finding on AFTER. The method overrides Handler.handle() in an anonymous class, has no callers that could be inlined, and carries no @InlineMe annotation.

Actual behavior

AFTER reports 1 InlineMeSuggester finding (This deprecated API looks inlineable. ...) on the @Deprecated public String handle() method; BEFORE reports 0.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions