Skip to content

Invoking private method on a CGLIB proxy should trigger a dedicated exception #30938

@samuelfac

Description

@samuelfac

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:

java.lang.NullPointerException: Cannot invoke "com.example.demo.service.MyService.sayHello()" because "this.myService" is null
	at com.example.demo.controller.MyController.get2(MyController.java:24) ~[classes/:na]
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na]
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
	at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na]
	at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205) ~[spring-web-6.0.11.jar:6.0.11]

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: coreIssues in core modules (aop, beans, core, context, expression)type: enhancementA general enhancement

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions