You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by ay...@apache.org on 2013/10/25 10:59:16 UTC
svn commit: r1535660 - in /cxf/trunk/core/src:
main/java/org/apache/cxf/attachment/LazyAttachmentCollection.java
test/java/org/apache/cxf/attachment/AttachmentDeserializerTest.java
Author: ay
Date: Fri Oct 25 08:59:16 2013
New Revision: 1535660
URL: http://svn.apache.org/r1535660
Log:
[CXF-5361] Attachments iterator may incorrectly handle its remove op
Modified:
cxf/trunk/core/src/main/java/org/apache/cxf/attachment/LazyAttachmentCollection.java
cxf/trunk/core/src/test/java/org/apache/cxf/attachment/AttachmentDeserializerTest.java
Modified: cxf/trunk/core/src/main/java/org/apache/cxf/attachment/LazyAttachmentCollection.java
URL: http://svn.apache.org/viewvc/cxf/trunk/core/src/main/java/org/apache/cxf/attachment/LazyAttachmentCollection.java?rev=1535660&r1=1535659&r2=1535660&view=diff
==============================================================================
--- cxf/trunk/core/src/main/java/org/apache/cxf/attachment/LazyAttachmentCollection.java (original)
+++ cxf/trunk/core/src/main/java/org/apache/cxf/attachment/LazyAttachmentCollection.java Fri Oct 25 08:59:16 2013
@@ -83,6 +83,7 @@ public class LazyAttachmentCollection
public Iterator<Attachment> iterator() {
return new Iterator<Attachment>() {
int current;
+ boolean removed;
public boolean hasNext() {
if (attachments.size() > current) {
@@ -106,11 +107,16 @@ public class LazyAttachmentCollection
public Attachment next() {
Attachment a = attachments.get(current);
current++;
+ removed = false;
return a;
}
public void remove() {
- attachments.remove(current);
+ if (removed) {
+ throw new IllegalStateException();
+ }
+ attachments.remove(--current);
+ removed = true;
}
};
Modified: cxf/trunk/core/src/test/java/org/apache/cxf/attachment/AttachmentDeserializerTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/core/src/test/java/org/apache/cxf/attachment/AttachmentDeserializerTest.java?rev=1535660&r1=1535659&r2=1535660&view=diff
==============================================================================
--- cxf/trunk/core/src/test/java/org/apache/cxf/attachment/AttachmentDeserializerTest.java (original)
+++ cxf/trunk/core/src/test/java/org/apache/cxf/attachment/AttachmentDeserializerTest.java Fri Oct 25 08:59:16 2013
@@ -23,9 +23,11 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PushbackInputStream;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
+import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -108,6 +110,17 @@ public class AttachmentDeserializerTest
assertTrue(attBody instanceof DelegatingInputStream);
attBody.close();
assertEquals(2, msg.getAttachments().size());
+ List<String> cidlist = new ArrayList<String>();
+ cidlist.add("xfire_logo.jpg");
+ cidlist.add("xfire_logo2.jpg");
+
+ for (Iterator<Attachment> it = msg.getAttachments().iterator(); it.hasNext();) {
+ Attachment a = it.next();
+ assertTrue(cidlist.remove(a.getId()));
+ it.remove();
+ }
+ assertEquals(0, cidlist.size());
+ assertEquals(0, msg.getAttachments().size());
}
@Test