spring-projects / spring-projects/spring-hateoas

DummyInvocationUtils.methodOn() Enhanced Controllers Throw NPE on Methods with void Return

Open
#1,700 0 comments 0 reactions 0 assignees View on GitHub

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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.