cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject [cxf] 01/02: [CXF-7754] Fix WrappedAttachments.toArray
Date Fri, 08 Jun 2018 19:36:49 GMT
This is an automated email from the ASF dual-hosted git repository.

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

commit 15323238564d80bdde07ec17aa271f1760c88ef1
Author: Daniel Kulp <dkulp@apache.org>
AuthorDate: Fri Jun 8 15:20:41 2018 -0400

    [CXF-7754] Fix WrappedAttachments.toArray
    
    (cherry picked from commit 8eab54c2a285ac91b0a04b8cd7e899d45f15b73a)
    
    # Conflicts:
    #	rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/context/WrappedAttachments.java
    #	rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/context/WrappedAttachmentsTest.java
---
 .../org/apache/cxf/jaxws/context/WrappedAttachments.java    |  4 ++--
 .../apache/cxf/jaxws/context/WrappedAttachmentsTest.java    | 13 +++++++++++--
 2 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/context/WrappedAttachments.java
b/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/context/WrappedAttachments.java
index 4b53c62..485dc38 100644
--- a/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/context/WrappedAttachments.java
+++ b/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/context/WrappedAttachments.java
@@ -70,8 +70,8 @@ class WrappedAttachments implements Set<Attachment> {
 
     @SuppressWarnings("unchecked")
     public <T> T[] toArray(T[] a) {
-        T[] copy = a.length == attachments.size() 
-            ? a : (T[])Array.newInstance(a.getClass(), attachments.size());
+        T[] copy = a.length == attachments.size()
+            ? a : (T[])Array.newInstance(a.getClass().getComponentType(), attachments.size());
         int i = 0;
         for (Map.Entry<String, DataHandler> entry : attachments.entrySet()) {
             Attachment o = cache.get(entry.getKey());
diff --git a/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/context/WrappedAttachmentsTest.java
b/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/context/WrappedAttachmentsTest.java
index 8ce0ef9..90c2d53 100644
--- a/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/context/WrappedAttachmentsTest.java
+++ b/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/context/WrappedAttachmentsTest.java
@@ -62,11 +62,20 @@ public class WrappedAttachmentsTest extends Assert {
         attachments.remove(attx);
         
         assertEquals(1, attachments.size());
-        
-        Attachment[] atts = attachments.toArray(new Attachment[attachments.size()]);
+
+        Attachment[] atts = attachments.toArray(new Attachment[0]); //NOPMD - explicitly
test this
+        assertEquals(1, atts.length);
+        assertEquals("att-1".equals(attx.getId()) ? "att-2" : "att-1", atts[0].getId());
+
+        atts = attachments.toArray(new Attachment[attachments.size()]); //NOPMD - explicitly
test this
         assertEquals(1, atts.length);
         assertEquals("att-1".equals(attx.getId()) ? "att-2" : "att-1", atts[0].getId());
         
+        Object o[] = attachments.toArray(); //NOPMD - explicitly test this
+        assertEquals(1, o.length);
+        Attachment a = (Attachment)o[0];
+        assertEquals("att-1".equals(attx.getId()) ? "att-2" : "att-1", a.getId());
+
         attachments.clear();
         assertTrue(attachments.isEmpty());
         assertTrue(content.isEmpty());

-- 
To stop receiving notification emails like this one, please contact
dkulp@apache.org.

Mime
View raw message