cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1478340 - in /cxf/trunk/rt/frontend/jaxrs/src: main/java/org/apache/cxf/jaxrs/impl/MetadataMap.java test/java/org/apache/cxf/jaxrs/impl/MetadataMapTest.java
Date Thu, 02 May 2013 12:08:44 GMT
Author: sergeyb
Date: Thu May  2 12:08:44 2013
New Revision: 1478340

URL: http://svn.apache.org/r1478340
Log:
If modifyable MetadataMap has unmodifiable Lists the replace them if needed

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/MetadataMap.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/MetadataMapTest.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/MetadataMap.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/MetadataMap.java?rev=1478340&r1=1478339&r2=1478340&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/MetadataMap.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/MetadataMap.java Thu
May  2 12:08:44 2013
@@ -92,10 +92,21 @@ public class MetadataMap<K, V> implement
     
     private void addValue(K key, V value, boolean last) {
         List<V> data = getList(key);
-        if (last) {
-            data.add(value);
-        } else {
-            data.add(0, value);
+        try {
+            if (last) {
+                data.add(value);
+            } else {
+                data.add(0, value);
+            }
+        } catch (UnsupportedOperationException ex) {
+            // this may happen if an unmodifiable List was set via put or putAll
+            if (!readOnly) {
+                List<V> newList = new ArrayList<V>(data);
+                put(key, newList);
+                addValue(key, value, last);
+            } else {
+                throw ex;
+            }
         }
     }
 

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/MetadataMapTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/MetadataMapTest.java?rev=1478340&r1=1478339&r2=1478340&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/MetadataMapTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/MetadataMapTest.java
Thu May  2 12:08:44 2013
@@ -20,6 +20,7 @@
 package org.apache.cxf.jaxrs.impl;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.LinkedList;
@@ -66,6 +67,21 @@ public class MetadataMapTest extends Ass
     }
     
     @Test
+    public void testAddFirstUnmodifiableListFirst() {
+        MetadataMap<String, Object> m = new MetadataMap<String, Object>();
+        m.put("baz", Arrays.<Object>asList("foo"));
+        List<Object> values = m.get("baz");
+        assertEquals(1, values.size());
+        assertEquals("foo", values.get(0));
+        
+        m.addFirst("baz", "clazz");
+        values = m.get("baz");
+        assertEquals(2, values.size());
+        assertEquals("clazz", values.get(0));
+        assertEquals("foo", values.get(1));
+    }
+    
+    @Test
     public void testAddAll() {
         MetadataMap<String, Object> m = new MetadataMap<String, Object>();
         List<Object> values = new ArrayList<Object>();



Mime
View raw message