Skip to content

DummyInvocationUtils.methodOn(…) fails for methods returning Object on JDK 17 #1638

@nealeu

Description

@nealeu

See this commit for the issue and the workaround.

In testing to upgrade to JDK 17 (note Lombok upgrade as per #1637 is required first), we found some test failures where we had Object as the return type (because String is final so cound not be used for enhancement).

The result is the following exception:

org.springframework.aop.framework.AopConfigException: Unexpected AOP exception; nested exception is java.lang.NullPointerException: Cannot invoke "Object.getClass()" because "cause" is null

	at org.springframework.aop.framework.CglibAopProxy.getProxy(CglibAopProxy.java:215)
	at org.springframework.aop.framework.ProxyFactory.getProxy(ProxyFactory.java:110)
	at org.springframework.hateoas.server.core.DummyInvocationUtils.getProxyWithInterceptor(DummyInvocationUtils.java:193)
	at org.springframework.hateoas.server.core.DummyInvocationUtils.access$000(DummyInvocationUtils.java:38)
	at org.springframework.hateoas.server.core.DummyInvocationUtils$InvocationRecordingMethodInterceptor.invoke(DummyInvocationUtils.java:90)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
	at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:750)
	at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:692)
	at org.springframework.hateoas.server.mvc.DummyInvocationUtilsUnitTest$SampleController$$EnhancerBySpringCGLIB$$920d7ce9.returnsStringAsObject(<generated>)

In our case we were able to change the method return type to CharSequence. I think for JDK 16+ Object is perhaps now not supportable - or some of the JDK9+ code in the AOP code is not handling Object due to some JDK changes, so this may need escalating into Spring core.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions