-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Bean classes cannot be instantiated when constructor calls method #10833
Comments
And what are you suggesting? |
It looks like |
That |
My suggestion? A null check in intercepted methods to bypass interception when called from constructors: public void setAge(String var1) {
(new MethodInterceptorChain(this.$interceptors[0], this.$target, this.$proxyMethods[0], new Object[]{var1})).proceed();
} to public void setAge(String var1) {
if(this.$interceptors != null) (new MethodInterceptorChain(this.$interceptors[0], this.$target, this.$proxyMethods[0], new Object[]{var1})).proceed();
else super.setAge(var1);
} |
Also just in case you want to know. |
Expected Behavior
The constructor of a class that is used for a bean should be able to call method within the constructor
example:
Actual Behaviour
The app compiles but at runntime the bean cannot be injected/instantiated:
Message: Cannot load from object array because "this.$interceptors" is null
since the proxy tries to intercept the call from the constructor which is not possible since the interceptors are only instantiated afterwards, eg:com.example.$ClassCallingInConstructor$Definition$Intercepted
callsClassCallingInConstructor.<init>()
-> calls$ClassCallingInConstructor$Definition$Intercepted.setAge()
which uses$interceptors
which is null since the object is not constructed yet and the interceptor classes constructor is only called after the original constructor!Steps To Reproduce
git clone https://github.com/nbrugger-tgm/micronaut-reproductions.git
cd micronaut-reproductions/micronaut-4-factory-regression
./gradlew test
The result is 2 failing tests, one using
@Singelton
for bean instantiation and one@Factory
Environment Information
OS: Kubuntu 23.10 x86_64
Micronaut: (referenced in the demo) 4.4.6
Example Application
https://github.com/nbrugger-tgm/micronaut-reproductions
Version
4.4.2
The text was updated successfully, but these errors were encountered: