spring-projects / spring-projects/spring-hateoas
DummyInvocationUtils.methodOn() Enhanced Controllers Throw NPE on Methods with void Return
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 1.1k
- Forks
- 476
- PR merge metrics
- No merged PRs in 30d
Description
When calling a controller method that returns void on a controller that has been enhanced with DummyInvocationUtils.methodOn(), a null pointer exception is thrown.
What led to this discovery was that I was looking for a way to write a utility method similar to WebMvcLinkBuilder.methodOn() for being able to build links with the faux-call style, except one that would work with controller methods that return void.
public class DummyTest {
@Test
public void dummy() {
Controller dummyController = DummyInvocationUtils.methodOn(Controller.class);
dummyController.deleteWidget(123L);
}
@RestController
@RequestMapping("/dummy")
public static class Controller {
@DeleteMapping("/{id}")
public void deleteWidget(@PathVariable("id") Long id) {
}
}
}
Unexpected AOP exception; nested exception is java.lang.NullPointerException
org.springframework.aop.framework.AopConfigException: Unexpected AOP exception; nested exception is java.lang.NullPointerException
at app//org.springframework.aop.framework.CglibAopProxy.getProxy(CglibAopProxy.java:215)
at app//org.springframework.aop.framework.ProxyFactory.getProxy(ProxyFactory.java:110)
at app//org.springframework.hateoas.server.core.DummyInvocationUtils.getProxyWithInterceptor(DummyInvocationUtils.java:165)
at app//org.springframework.hateoas.server.core.DummyInvocationUtils.access$000(DummyInvocationUtils.java:38)
at app//org.springframework.hateoas.server.core.DummyInvocationUtils$InvocationRecordingMethodInterceptor.invoke(DummyInvocationUtils.java:90)
at app//org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at app//org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:750)
at app//org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:692)
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the provided DummyTest with DummyInvocationUtils.methodOn() and the void Controller.deleteWidget method. Then inspect DummyInvocationUtils.getProxyWithInterceptor and InvocationRecordingMethodInterceptor, both named in the stack trace. Done means invoking the void method completes without the reported NullPointerException.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100