java.lang.IllegalArgumentException: Invalid handler method return value: HelloResponse@caf0ed

There are no available Samebug tips for this exception. Do you have an idea how to solve this issue? A short tip would help users who saw this issue last week.

  • Spring MVC @ExceptionHandler controller methods support a flexible argument list and return value, similiar to @RequestMapping-annotated methods. One option that is supported by @RequestMapping methods but not @ExceptionHandler methods is returning naked bean objects from the exception handler method. For example, this type of exception handler method would be very convenient, especially when building RESTful services using a MarshallingView (the important detail is the "HelloResponse" return value from the handleBindException method): {code} @Controller @RequestMapping("/Hello") public class HelloController { @RequestMapping(value = "/greet", method = RequestMethod.GET) public HelloResponse greetGet(@Valid HelloRequest request) { String message = "Hello, " + request.getTitle() + " " + request.getName(); return new HelloResponse(message); } @ExceptionHandler(BindException.class) public HelloResponse handleBindException(BindException be) { List<FieldError> errors = be.getFieldErrors(); HelloResponse response = new HelloResponse(); for (FieldError error : errors) { response.addError(error.toString()); } return response; } } {code} With a response object that looks like this: {code} @XmlRootElement(name = "response") public class HelloResponse { private String message; private List<String> errors; // getters and setters } {code} Currently this code will throw an exception when the exception handler method returns to the framework: {code} java.lang.IllegalArgumentException: Invalid handler method return value: HelloResponse@caf0ed at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerExceptionResolver.getModelAndView(AnnotationMethodHandlerExceptionResolver.java:353) at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerExceptionResolver.doResolveException(AnnotationMethodHandlerExceptionResolver.java:101) at org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver.resolveException(AbstractHandlerExceptionResolver.java:109) at org.springframework.web.servlet.DispatcherServlet.processHandlerException(DispatcherServlet.java:1004) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:792) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:716) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:647) at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:552) at javax.servlet.http.HttpServlet.service(HttpServlet.java:707) at javax.servlet.http.HttpServlet.service(HttpServlet.java:820) {code}
    via by Scott Frederick,
  • Spring MVC @ExceptionHandler controller methods support a flexible argument list and return value, similiar to @RequestMapping-annotated methods. One option that is supported by @RequestMapping methods but not @ExceptionHandler methods is returning naked bean objects from the exception handler method. For example, this type of exception handler method would be very convenient, especially when building RESTful services using a MarshallingView (the important detail is the "HelloResponse" return value from the handleBindException method): {code} @Controller @RequestMapping("/Hello") public class HelloController { @RequestMapping(value = "/greet", method = RequestMethod.GET) public HelloResponse greetGet(@Valid HelloRequest request) { String message = "Hello, " + request.getTitle() + " " + request.getName(); return new HelloResponse(message); } @ExceptionHandler(BindException.class) public HelloResponse handleBindException(BindException be) { List<FieldError> errors = be.getFieldErrors(); HelloResponse response = new HelloResponse(); for (FieldError error : errors) { response.addError(error.toString()); } return response; } } {code} With a response object that looks like this: {code} @XmlRootElement(name = "response") public class HelloResponse { private String message; private List<String> errors; // getters and setters } {code} Currently this code will throw an exception when the exception handler method returns to the framework: {code} java.lang.IllegalArgumentException: Invalid handler method return value: HelloResponse@caf0ed at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerExceptionResolver.getModelAndView(AnnotationMethodHandlerExceptionResolver.java:353) at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerExceptionResolver.doResolveException(AnnotationMethodHandlerExceptionResolver.java:101) at org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver.resolveException(AbstractHandlerExceptionResolver.java:109) at org.springframework.web.servlet.DispatcherServlet.processHandlerException(DispatcherServlet.java:1004) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:792) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:716) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:647) at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:552) at javax.servlet.http.HttpServlet.service(HttpServlet.java:707) at javax.servlet.http.HttpServlet.service(HttpServlet.java:820) {code}
    via by Scott Frederick,
  • SpringMVC Restful Web Service
    via Stack Overflow by devdar
    ,
  • This is a duplicate of bug SPR-7637 and SPR-6692. SPR-7637 is marked as resolved, claiming the issue has been addressed, but it is not. I am trying to do exactly this, and I get the following exception: {code} 00:50:42.949 ERROR annotation.AnnotationMethodHandlerExceptionResolver (AnnotationMethodHandlerExceptionResolver.java:147) Invoking request method resulted in exception : public org.springframework.http.ResponseEntity com.latencyzero.gamecenter.web.ServiceController.handleException(java.lang.Exception) java.lang.IllegalArgumentException: Invalid handler method return value: <500 Internal Server Error,{"resultMsg":"Could not open Hibernate Session for transaction; nested exception is org.hibernate.exception.JDBCConnectionException: Cannot open connection","result":1},{Content-Type=[application/json;charset=UTF-8]}> at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerExceptionResolver.getModelAndView(AnnotationMethodHandlerExceptionResolver.java:414) at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerExceptionResolver.doResolveException(AnnotationMethodHandlerExceptionResolver.java:144) at org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver.resolveException(AbstractHandlerExceptionResolver.java:136) at org.springframework.web.servlet.DispatcherServlet.processHandlerException(DispatcherServlet.java:1148) at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:985) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:939) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:917) at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:813) at javax.servlet.http.HttpServlet.service(HttpServlet.java:120) at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:798) at javax.servlet.http.HttpServlet.service(HttpServlet.java:97) {code} My handler is declared as follows: {code} @ExceptionHandler(org.springframework.web.bind.MissingServletRequestParameterException.class) public ResponseEntity<String> handleException(org.springframework.web.bind.MissingServletRequestParameterException inEx) { ... } {code} According to the [3.2.0.RC2 docs|http://static.springsource.org/spring/docs/3.2.0.RC2/javadoc-api/org/springframework/web/bind/annotation/ExceptionHandler.html], it is now acceptable. But the code seems to handle all cases except ResponseEntity: [https://github.com/SpringSource/spring-framework/blob/master/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/annotation/AnnotationMethodHandlerExceptionResolver.java#L376]
    via by Rick Mann,
  • This is a duplicate of bug SPR-7637 and SPR-6692. SPR-7637 is marked as resolved, claiming the issue has been addressed, but it is not. I am trying to do exactly this, and I get the following exception: {code} 00:50:42.949 ERROR annotation.AnnotationMethodHandlerExceptionResolver (AnnotationMethodHandlerExceptionResolver.java:147) Invoking request method resulted in exception : public org.springframework.http.ResponseEntity com.latencyzero.gamecenter.web.ServiceController.handleException(java.lang.Exception) java.lang.IllegalArgumentException: Invalid handler method return value: <500 Internal Server Error,{"resultMsg":"Could not open Hibernate Session for transaction; nested exception is org.hibernate.exception.JDBCConnectionException: Cannot open connection","result":1},{Content-Type=[application/json;charset=UTF-8]}> at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerExceptionResolver.getModelAndView(AnnotationMethodHandlerExceptionResolver.java:414) at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerExceptionResolver.doResolveException(AnnotationMethodHandlerExceptionResolver.java:144) at org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver.resolveException(AbstractHandlerExceptionResolver.java:136) at org.springframework.web.servlet.DispatcherServlet.processHandlerException(DispatcherServlet.java:1148) at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:985) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:939) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:917) at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:813) at javax.servlet.http.HttpServlet.service(HttpServlet.java:120) at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:798) at javax.servlet.http.HttpServlet.service(HttpServlet.java:97) {code} My handler is declared as follows: {code} @ExceptionHandler(org.springframework.web.bind.MissingServletRequestParameterException.class) public ResponseEntity<String> handleException(org.springframework.web.bind.MissingServletRequestParameterException inEx) { ... } {code} According to the [3.2.0.RC2 docs|http://static.springsource.org/spring/docs/3.2.0.RC2/javadoc-api/org/springframework/web/bind/annotation/ExceptionHandler.html], it is now acceptable. But the code seems to handle all cases except ResponseEntity: [https://github.com/SpringSource/spring-framework/blob/master/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/annotation/AnnotationMethodHandlerExceptionResolver.java#L376]
    via by Rick Mann,
  • [Mifos-developer] Installation Error
    via by srinivasa Rao Yedida,
    • java.lang.IllegalArgumentException: Invalid handler method return value: HelloResponse@caf0ed at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerExceptionResolver.getModelAndView(AnnotationMethodHandlerExceptionResolver.java:353) at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerExceptionResolver.doResolveException(AnnotationMethodHandlerExceptionResolver.java:101) at org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver.resolveException(AbstractHandlerExceptionResolver.java:109) at org.springframework.web.servlet.DispatcherServlet.processHandlerException(DispatcherServlet.java:1004) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:792) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:716) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:647) at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:552) at javax.servlet.http.HttpServlet.service(HttpServlet.java:707) at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)

    Users with the same issue

    Unknown visitor1 times, last one,