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

Spring JIRA | Scott Frederick | 7 years ago
tip
Your exception is missing from the Samebug knowledge base.
Here are the best solutions we found on the Internet.
Click on the to mark the helpful solution and get rewards for you help.
  1. 0

    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}

    Spring JIRA | 7 years ago | Scott Frederick
    java.lang.IllegalArgumentException: Invalid handler method return value: HelloResponse@caf0ed
  2. 0

    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}

    Spring JIRA | 7 years ago | Scott Frederick
    java.lang.IllegalArgumentException: Invalid handler method return value: HelloResponse@caf0ed
  3. 0

    SpringMVC Restful Web Service

    Stack Overflow | 4 years ago | devdar
    java.lang.IllegalArgumentException: Invalid handler method return value: false
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    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]

    Spring JIRA | 4 years ago | Rick Mann
    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]}>

    1 unregistered visitors
    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. java.lang.IllegalArgumentException

      Invalid handler method return value: HelloResponse@caf0ed

      at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerExceptionResolver.getModelAndView()
    2. Spring MVC
      FrameworkServlet.doGet
      1. org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerExceptionResolver.getModelAndView(AnnotationMethodHandlerExceptionResolver.java:353)
      2. org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerExceptionResolver.doResolveException(AnnotationMethodHandlerExceptionResolver.java:101)
      3. org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver.resolveException(AbstractHandlerExceptionResolver.java:109)
      4. org.springframework.web.servlet.DispatcherServlet.processHandlerException(DispatcherServlet.java:1004)
      5. org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:792)
      6. org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:716)
      7. org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:647)
      8. org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:552)
      8 frames
    3. JavaServlet
      HttpServlet.service
      1. javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
      2. javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
      2 frames