Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code generation should only apply shortcut if the target method is not ambiguous #29278

Closed
snicoll opened this issue Oct 7, 2022 · 0 comments
Assignees
Labels
theme: aot An issue related to Ahead-of-time processing type: bug A general bug
Milestone

Comments

@snicoll
Copy link
Member

snicoll commented Oct 7, 2022

Consider the following bean definition:

RootBeanDefinition beanDefinition = (RootBeanDefinition) BeanDefinitionBuilder
		.rootBeanDefinition(DocumentBuilderFactory.class).setFactoryMethod("newNSInstance").getBeanDefinition();

Compilation of the generated code fails as follows:

reference to withGenerator is ambiguous
  both method withGenerator(org.springframework.util.function.ThrowingBiFunction<org.springframework.beans.factory.support.RegisteredBean,org.springframework.beans.factory.aot.AutowiredArguments,T>) in org.springframework.beans.factory.aot.BeanInstanceSupplier and method withGenerator(org.springframework.util.function.ThrowingSupplier<T>) in org.springframework.beans.factory.aot.BeanInstanceSupplier match /com/example/TestTarget__TestCode.java 21:148
incompatible types: invalid method reference
    incompatible types: org.springframework.beans.factory.support.RegisteredBean cannot be converted to java.lang.String /com/example/TestTarget__TestCode.java 21:163

The reason is that DocumentBuilderFactory has two static methods named newNSInstance. A no-arg one and a two-args one. We have a similar arrangement for withGenerator that can take a BiFunction or a Supplier.

@snicoll snicoll added type: bug A general bug theme: aot An issue related to Ahead-of-time processing labels Oct 7, 2022
@snicoll snicoll added this to the 6.0.x milestone Oct 7, 2022
Devashish2293 added a commit to Devashish2293/spring-framework that referenced this issue Jun 26, 2023
@sdeleuze sdeleuze modified the milestones: 6.0.x, 6.1.x Jul 4, 2023
@snicoll snicoll modified the milestones: 6.1.x, 6.0.11 Jul 12, 2023
@snicoll snicoll self-assigned this Jul 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
theme: aot An issue related to Ahead-of-time processing type: bug A general bug
Projects
None yet
2 participants