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:59:10 GMT
Repository: cxf
Updated Branches:
  refs/heads/2.6.x-fixes b3351649d -> a4f720e84


[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/a4f720e8
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/a4f720e8
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/a4f720e8

Branch: refs/heads/2.6.x-fixes
Commit: a4f720e84c2717c1f6cb8286ac15c5db79dbd684
Parents: b335164
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:58:28 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/a4f720e8/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 702af33..5772ef9 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
@@ -194,13 +194,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(types, params);
         } else if (types.containsKey(ParameterType.REQUEST_BODY))  {

http://git-wip-us.apache.org/repos/asf/cxf/blob/a4f720e8/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 ecd1b79..39066e0 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
@@ -418,9 +418,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/a4f720e8/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 a5ac821..980a5cf 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
@@ -347,6 +347,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