-
Notifications
You must be signed in to change notification settings - Fork 37.7k
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
Invoking private method on a CGLIB proxy should trigger a dedicated exception #30938
Comments
Thanks for the sample. Your aspect does not work on the private method and it looks like the call to the private method is done on the raw instance, and said instance has not been initialized properly. Perhaps the creation of the aspect lead to an early initialization of the bean. It's a bit odd so we'd need to investigate a bit more. |
So the Aspect has nothing to do with the issue, except the fact it triggers the creation of a proxy. The same. could happen with any stereotype on the controller that trigger the same thing (e.g. We'll revisit this to trigger a proper exception upfront, rather than calling the private method on the proxy via reflection. Either way, this scenario won't be supported so you'll have to revisit your controller so that the method isn't private. |
Yes, I already changed all my methods to public, but it took me a few hours to find out what the problem was because I didn't find anything about it, so I opened the issue. Thanks |
I have created a simple test that reproduces the error:
|
I also had a similar situation. While developing a Handler, when I applied an AOP-annotated method to a simple operation (for example, returning the string "success"), it executed successfully. However, when debugging, I could see that it was being executed from the Enhancer class. But when it comes to executing operations that depend on classes like Service through dependency injection, the injected class ends up being null. I believe that the statement about a proxy object being created for a private method itself is incorrect. If there is any related information, please provide a posting, + My guess is that the generated proxy object does not have dependency injection, but the original object has dependency injection, so the enhancer calls the method's behavior, which seems to be working as null. This seems to need modification. |
I have registered the above comment as a cglib issue. cglib/cglib#223 |
I created a ExecutionTimeAdvice.java to log the runtime of all my controller methods using @aspect.
When i call the public (http://localhost:8080/) method works perfectly, but when I call the private method (http://localhost:8080/2) my @Autowired service is not instantiated:
but if I remove the filter everything works.
You can download the project here: demo.zip
Tests were performed on the following versions:: 2.7.14 (java8) and 3.1.2 (java17)
The text was updated successfully, but these errors were encountered: