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

Reordering constructors breaks intercepted factory bean compilation #10834

Open
nbrugger-tgm opened this issue May 17, 2024 · 0 comments
Open
Labels
type: bug Something isn't working

Comments

@nbrugger-tgm
Copy link

nbrugger-tgm commented May 17, 2024

Expected Behavior

When compiling a factory that creates a bean with 2 constructors, it wrongly fails

Given the factory (not @NotNull is important for interceptor creation, which is another bug #10836)

@Factory
public class BrokenFactory {
    @Bean
    public @NotNull TwoConstructorClass twoConstructorClass() {
        return new TwoConstructorClass();
    }
}

And TwoConstructorClass being:

public class TwoConstructorClass {
    public TwoConstructorClass(String age) {
    }
    public TwoConstructorClass() {
        this("10");
    }
}

I would expect compilation to work

Actual Behaviour

Compilation fails with

error: The produced type from a factory which has AOP proxy advice specified must define an accessible no arguments constructor. Proxying types with constructor arguments can lead to unexpected behaviour. See the javadoc for for Around.ProxyTargetConstructorMode for more information and possible solutions: classCallingInConstructor
    public @NotNull TwoConstructorClass classCallingInConstructor() {

but (only) when switching the constructors (so that the parameterless one is first) the error goes away

public class TwoConstructorClass {
    public TwoConstructorClass() {
        this("10");
    }
    public TwoConstructorClass(String age) {
    }
}

Steps To Reproduce

  1. git clone https://github.com/nbrugger-tgm/micronaut-reproductions
  2. cd micronaut-reproductions/micronaut-4-factory-regression-2
  3. gradle classes

Environment Information

  • OS: Kubuntu
  • JDK: 17

Example Application

https://github.com/nbrugger-tgm/micronaut-reproductions

Version

4.4.2

@graemerocher graemerocher added the type: bug Something isn't working label May 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants