cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject git commit: [CXF-5749] Avoiding NPE if client proxy is given null body parameter
Date Tue, 20 May 2014 15:23:38 GMT
Repository: cxf
Updated Branches:
  refs/heads/2.7.x-fixes a3af72488 -> 3248da800


[CXF-5749] Avoiding NPE if client proxy is given null body parameter


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/3248da80
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/3248da80
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/3248da80

Branch: refs/heads/2.7.x-fixes
Commit: 3248da800fdf25f5bd962b962b7ff2d9d98cd225
Parents: a3af724
Author: Sergey Beryozkin <sberyozkin@talend.com>
Authored: Tue May 20 16:12:16 2014 +0100
Committer: Sergey Beryozkin <sberyozkin@talend.com>
Committed: Tue May 20 16:23:27 2014 +0100

----------------------------------------------------------------------
 .../org/apache/cxf/jaxrs/client/ClientProxyImpl.java     |  5 ++++-
 .../java/org/apache/cxf/systest/jaxrs/BookStore.java     |  6 ++++--
 .../cxf/systest/jaxrs/JAXRSClientServerBookTest.java     | 11 +++++++++++
 3 files changed, 19 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/3248da80/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
index 08b7327..102d3d1 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
@@ -203,13 +203,16 @@ public class ClientProxyImpl extends AbstractClient implements
         
         headers.putAll(paramHeaders);
         setRequestHeaders(headers, ori, types.containsKey(ParameterType.FORM), 
-            bodyIndex == -1 ? null : params[bodyIndex].getClass(), m.getReturnType());
+            bodyIndex == -1 || params[bodyIndex] == null ? null : params[bodyIndex].getClass(),
m.getReturnType());
         
         getState().setTemplates(getTemplateParametersMap(ori.getURITemplate(), pathParams));
         
         Object body = null;
         if (bodyIndex != -1) {
             body = params[bodyIndex];
+            if (body == null) {
+                bodyIndex = -1;
+            }
         } else if (types.containsKey(ParameterType.FORM))  {
             body = handleForm(m, params, types, beanParamsList);
         } else if (types.containsKey(ParameterType.REQUEST_BODY))  {

http://git-wip-us.apache.org/repos/asf/cxf/blob/3248da80/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
index c9f46ff..d8fc681 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
@@ -562,9 +562,11 @@ public class BookStore {
     @Path("/collectionBook")
     @Produces({"application/xml", "application/json" })
     @Consumes({"application/xml", "application/json" })
-    public List<Book> postBookGetCollection(Book book) throws Exception {
+    public List<Book> postBookGetCollection(@Nullable Book book) throws Exception {
         List<Book> list = new ArrayList<Book>();
-        list.add(book);
+        if (book != null) {
+            list.add(book);
+        }
         return list;
     }
     

http://git-wip-us.apache.org/repos/asf/cxf/blob/3248da80/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
index 23b2e50..504f9a9 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
@@ -613,6 +613,17 @@ public class JAXRSClientServerBookTest extends AbstractBusClientServerTestBase
{
     }
     
     @Test
+    public void testPostNullGetEmptyCollectionProxy() throws Exception {
+        
+        String endpointAddress = "http://localhost:" + PORT; 
+        BookStore bs = JAXRSClientFactory.create(endpointAddress, BookStore.class);
+        List<Book> books = bs.postBookGetCollection(null);
+        assertNotNull(books);
+        assertEquals(0, books.size());
+        
+    }
+    
+    @Test
     public void testPostObjectGetCollection() throws Exception {
         
         String endpointAddress =


Mime
View raw message