Skip to content

Error when AutoFactory implementing methods cannot match create() - #2152

Open
tanvir-ux wants to merge 1 commit into
google:mainfrom
tanvir-ux:fix-autofactory-unmatched-implementing-method
Open

tanvir-ux wants to merge 1 commit into
google:mainfrom
tanvir-ux:fix-autofactory-unmatched-implementing-method

Conversation

@tanvir-ux

Copy link
Copy Markdown
Contributor

Summary

  • When an @AutoFactory(implementing = …) (or extending) abstract method has no matching factory create overload, AutoFactory used to emit a forwarding stub return create(args).
  • If that abstract method was itself named create, the stub called itself and threw StackOverflowError at runtime. The usual trigger is forgetting @Provided on a constructor parameter, which silently turns that parameter into an extra factory argument (fixes AutoFactory: missing @Provided leads to StackOverflowError #697).
  • The processor now reports a compile-time error that names the unmatched method and points at @Provided, instead of generating the recursive stub.

Test plan

  • mvn test in factory/ — AutoFactoryProcessorTest 185 tests (7 skipped), AutoFactoryProcessorNegativeTest including new missingProvidedLeadsToUnmatchedInterfaceMethod
  • mvn verify in factory/ — unit tests + invoker ITs passed
  • Reviewer: compile the AutoFactory: missing @Provided leads to StackOverflowError #697 sample (@AutoFactory(implementing = Factory.class) with a missing @Provided) and confirm a clear error on @AutoFactory rather than a runtime StackOverflowError

Previously, an abstract method from an `implementing` (or `extending`)
type that did not match any factory `create` overload still produced a
forwarding stub of the form `return create(args)`. When the interface
method itself was named `create`, that stub called itself and caused a
StackOverflowError at runtime — typically after forgetting `@Provided`
on a constructor parameter (issue google#697).

Fail compilation with a diagnostic that explains the mismatch and
points at `@Provided`, and add a negative compilation test for the
reported case.
@kluever kluever added type=defect Bug, not working as expected Component: factory labels Sep 29, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Component: factory type=defect Bug, not working as expected

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AutoFactory: missing @Provided leads to StackOverflowError

2 participants