From 1149f2d9164c7f8aabab9fecb66c6cc320ee8ca0 Mon Sep 17 00:00:00 2001 From: Jesse Vincent Date: Fri, 26 Nov 2010 03:53:15 +0000 Subject: [PATCH] refactor getHeaders and removeHeaders to use a common method and an iterator to address a Market FC: java.util.ConcurrentModificationException at java.util.ArrayList$ArrayListIterator.next(ArrayList.java:573) at com.fsck.k9.mail.internet.MimeHeader.getHeader(MimeHeader.java:87) at com.fsck.k9.mail.internet.MimeHeader.getFirstHeader(MimeHeader.java:51) at com.fsck.k9.mail.internet.MimeMessage.getFirstHeader(MimeMessage.java:437) at com.fsck.k9.mail.internet.MimeMessage.getContentType(MimeMessage.java:130) at com.fsck.k9.mail.internet.MimeMessage.getMimeType(MimeMessage.java:159) at com.fsck.k9.mail.internet.MimeUtility.findFirstPartByMimeType(MimeUtility.java:971) at com.fsck.k9.crypto.Apg.isEncrypted(Apg.java:464) at com.fsck.k9.activity.MessageView.updateDecryptLayout(MessageView.java:2702) at com.fsck.k9.activity.MessageView$Listener$6.run(MessageView.java:2466) at android.os.Handler.handleCallback(Handler.java:587) at android.os.Handler.dispatchMessage(Handler.java:92) at android.os.Looper.loop(Looper.java:144) at android.app.ActivityThread.main(ActivityThread.java:4937) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:521) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) --- src/com/fsck/k9/mail/internet/MimeHeader.java | 35 ++++++++++--------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/src/com/fsck/k9/mail/internet/MimeHeader.java b/src/com/fsck/k9/mail/internet/MimeHeader.java index 1b260cf9f..6a2672a93 100644 --- a/src/com/fsck/k9/mail/internet/MimeHeader.java +++ b/src/com/fsck/k9/mail/internet/MimeHeader.java @@ -83,14 +83,7 @@ public class MimeHeader public String[] getHeader(String name) { - ArrayList values = new ArrayList(); - for (Field field : mFields) - { - if (field.name.equalsIgnoreCase(name)) - { - values.add(field.value); - } - } + ArrayList values = findHeaders(name); if (values.size() == 0) { return null; @@ -100,17 +93,27 @@ public class MimeHeader public void removeHeader(String name) { - ArrayList removeFields = new ArrayList(); - for (Field field : mFields) - { - if (field.name.equalsIgnoreCase(name)) - { - removeFields.add(field); - } - } + + ArrayList removeFields = findHeaders(name); mFields.removeAll(removeFields); } + private ArrayList findHeaders(String name) { + ArrayList values = new ArrayList(); + Iterator iter = mFields.iterator(); + while (iter.hasNext()) + { + Field field = iter.next(); + if (field.name.equalsIgnoreCase(name) ) + { + values.add(field.value); + } + } + + return values; + } + + public void writeTo(OutputStream out) throws IOException, MessagingException { BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(out), 1024);