[cxf] branch 3.3.x-fixes updated: CXF-8376: Misleading Error Message From UriBuilder.path(Method) (#727)

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[cxf] branch 3.3.x-fixes updated: CXF-8376: Misleading Error Message From UriBuilder.path(Method) (#727)

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

reta pushed a commit to branch 3.3.x-fixes
in repository https://gitbox.apache.org/repos/asf/cxf.git


The following commit(s) were added to refs/heads/3.3.x-fixes by this push:
     new 4492eba  CXF-8376: Misleading Error Message From UriBuilder.path(Method) (#727)
4492eba is described below

commit 4492eba67b18c19bb76018f2f94956bede7a3856
Author: James Carman <[hidden email]>
AuthorDate: Thu Nov 19 17:59:44 2020 -0500

    CXF-8376: Misleading Error Message From UriBuilder.path(Method) (#727)
   
    Signed-off-by: James Carman <[hidden email]>
---
 .../main/java/org/apache/cxf/jaxrs/impl/UriBuilderImpl.java   |  2 +-
 .../java/org/apache/cxf/jaxrs/impl/UriBuilderImplTest.java    | 11 ++++++++++-
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriBuilderImpl.java b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriBuilderImpl.java
index 01531bd..fc614b5 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriBuilderImpl.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriBuilderImpl.java
@@ -513,7 +513,7 @@ public class UriBuilderImpl extends UriBuilder implements Cloneable {
         }
         Path ann = method.getAnnotation(Path.class);
         if (ann == null) {
-            throw new IllegalArgumentException("Method '" + method.getClass().getCanonicalName() + "."
+            throw new IllegalArgumentException("Method '" + method.getDeclaringClass().getCanonicalName() + "."
                                                + method.getName() + "' is not annotated with Path");
         }
         // path(String) decomposes multi-segment path when necessary
diff --git a/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/UriBuilderImplTest.java b/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/UriBuilderImplTest.java
index 784da6e..197e724 100644
--- a/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/UriBuilderImplTest.java
+++ b/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/UriBuilderImplTest.java
@@ -37,13 +37,18 @@ import org.apache.cxf.jaxrs.resources.BookStore;
 import org.apache.cxf.jaxrs.resources.UriBuilderWrongAnnotations;
 import org.apache.cxf.jaxrs.utils.JAXRSUtils;
 
+import org.junit.Rule;
 import org.junit.Test;
+import org.junit.rules.ExpectedException;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.fail;
 
 public class UriBuilderImplTest {
 
+    @Rule
+    public ExpectedException thrown = ExpectedException.none();
+
     @Test
     public void testFromUriRelativePath() throws Exception {
         UriBuilder builder = UriBuilder.fromUri("path");
@@ -854,8 +859,12 @@ public class UriBuilderImplTest {
         new UriBuilderImpl().path((Method)null).build();
     }
 
-    @Test(expected = IllegalArgumentException.class)
+    @Test
     public void testAddPathMethodNoAnnotation() throws Exception {
+        thrown.expect(IllegalArgumentException.class);
+        thrown.expectMessage(
+                String.format("Method '%s.getBook' is not annotated with Path",
+                BookStore.class.getCanonicalName()));
         Method noAnnot = BookStore.class.getMethod("getBook", String.class);
         new UriBuilderImpl().path(noAnnot).build();
     }