You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@juneau.apache.org by ja...@apache.org on 2019/06/28 01:09:06 UTC

[juneau] branch master updated: JUNEAU-107 - IllegalArgumentException in DefaultHandler.handle()

This is an automated email from the ASF dual-hosted git repository.

jamesbognar pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/juneau.git


The following commit(s) were added to refs/heads/master by this push:
     new 18a3ae5  JUNEAU-107 - IllegalArgumentException in DefaultHandler.handle()
18a3ae5 is described below

commit 18a3ae5643b9b33ad7013a7b59034042d75fe4aa
Author: JamesBognar <ja...@apache.org>
AuthorDate: Thu Jun 27 21:07:46 2019 -0400

    JUNEAU-107 - IllegalArgumentException in DefaultHandler.handle()
---
 .../org/apache/juneau/rest/exception/BasicTest.java    | 18 ++++++++++++++++++
 .../java/org/apache/juneau/rest/RestMethodContext.java |  5 ++++-
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/juneau-rest/juneau-rest-server-utest/src/test/java/org/apache/juneau/rest/exception/BasicTest.java b/juneau-rest/juneau-rest-server-utest/src/test/java/org/apache/juneau/rest/exception/BasicTest.java
index da03dcc..0a423c4 100644
--- a/juneau-rest/juneau-rest-server-utest/src/test/java/org/apache/juneau/rest/exception/BasicTest.java
+++ b/juneau-rest/juneau-rest-server-utest/src/test/java/org/apache/juneau/rest/exception/BasicTest.java
@@ -18,6 +18,7 @@ import static org.apache.juneau.rest.testutils.TestUtils.*;
 import org.apache.juneau.dto.swagger.*;
 import org.apache.juneau.json.*;
 import org.apache.juneau.rest.annotation.*;
+import org.apache.juneau.rest.helper.*;
 import org.apache.juneau.rest.mock2.*;
 import org.junit.*;
 import org.junit.runners.*;
@@ -956,4 +957,21 @@ public class BasicTest {
 		ResponseInfo ri = f.getPaths().get("/variantAlsoNegotiates").get("get").getResponse(VariantAlsoNegotiates.CODE);
 		assertEquals(VariantAlsoNegotiates.MESSAGE, ri.getDescription());
 	}
+
+	//-----------------------------------------------------------------------------------------------------------------
+	// Thrown object doesn't match return type.
+	//-----------------------------------------------------------------------------------------------------------------
+
+	@RestResource
+	public static class G {
+		@RestMethod
+		public SeeOtherRoot thrownObjectDoesntMatchReturnType() throws Exception { throw new NotFound(); }
+	}
+
+	static MockRest g = MockRest.create(G.class).build();
+
+	@Test
+	public void g01_thrownObjectDoesntMatchReturnType() throws Exception {
+		g.get("/thrownObjectDoesntMatchReturnType").execute().assertStatus(404);
+	}
 }
diff --git a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestMethodContext.java b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestMethodContext.java
index 0cf0fbf..02d75dc 100644
--- a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestMethodContext.java
+++ b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestMethodContext.java
@@ -806,8 +806,11 @@ public class RestMethodContext extends BeanContext implements Comparable<RestMet
 			} catch (InvocationTargetException e) {
 				Throwable e2 = e.getTargetException();		// Get the throwable thrown from the doX() method.
 				res.setStatus(500);
-				if (getResponseBodyMeta(e2) != null || getResponseBeanMeta(e2) != null) {
+				ResponsePartMeta rpm = getResponseBodyMeta(e2);
+				ResponseBeanMeta rbm = getResponseBeanMeta(e2);
+				if (rpm != null || rbm != null) {
 					res.setOutput(e2);
+					res.setResponseMeta(rbm);
 				} else {
 					throw e;
 				}