From 79976065504d18513291614d12448b3b24ed9265 Mon Sep 17 00:00:00 2001 From: Ricki Hirner Date: Tue, 19 Apr 2016 21:56:05 +0200 Subject: [PATCH] Minor optimizations * catch IllegalArgumentException from HttpUrl in DavResourceFinder (caused crash when logging in with email "test@server/withslash") * use IteratorChain in DavService collection enumeration --- app/build.gradle | 1 + .../main/java/at/bitfire/davdroid/DavService.java | 15 +++++++++------ .../davdroid/ui/setup/DavResourceFinder.java | 2 +- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index fa794659..4944d0c0 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -75,6 +75,7 @@ dependencies { compile 'dnsjava:dnsjava:2.1.7' compile 'org.apache.commons:commons-lang3:3.4' + compile 'org.apache.commons:commons-collections4:4.1' // for tests androidTestCompile 'com.squareup.okhttp3:mockwebserver:3.2.0' diff --git a/app/src/main/java/at/bitfire/davdroid/DavService.java b/app/src/main/java/at/bitfire/davdroid/DavService.java index 0cd78a2d..58492087 100644 --- a/app/src/main/java/at/bitfire/davdroid/DavService.java +++ b/app/src/main/java/at/bitfire/davdroid/DavService.java @@ -27,6 +27,9 @@ import android.support.annotation.Nullable; import android.support.v7.app.NotificationCompat; import android.text.TextUtils; +import org.apache.commons.collections4.iterators.IteratorChain; +import org.apache.commons.collections4.iterators.SingletonIterator; + import java.io.IOException; import java.util.HashSet; import java.util.Iterator; @@ -221,16 +224,16 @@ public class DavService extends Service { if (info.selected) selectedCollections.add(HttpUrl.parse(info.url)); - for (Iterator iterator = homeSets.iterator(); iterator.hasNext(); ) { - HttpUrl homeSet = iterator.next(); + for (Iterator itHomeSets = homeSets.iterator(); itHomeSets.hasNext(); ) { + HttpUrl homeSet = itHomeSets.next(); App.log.fine("Listing home set " + homeSet); DavResource dav = new DavResource(httpClient, homeSet); try { dav.propfind(1, CollectionInfo.DAV_PROPERTIES); - Set selfAndMembers = new HashSet<>(dav.members); - selfAndMembers.add(dav); - for (DavResource member : selfAndMembers) { + IteratorChain itCollections = new IteratorChain<>(dav.members.iterator(), new SingletonIterator(dav)); + while (itCollections.hasNext()) { + DavResource member = itCollections.next(); CollectionInfo info = CollectionInfo.fromDavResource(member); info.confirmed = true; App.log.log(Level.FINE, "Found collection", info); @@ -242,7 +245,7 @@ public class DavService extends Service { } catch(HttpException e) { if (e.status == 403 || e.status == 404 || e.status == 410) // delete home set only if it was not accessible (40x) - iterator.remove(); + itHomeSets.remove(); } } diff --git a/app/src/main/java/at/bitfire/davdroid/ui/setup/DavResourceFinder.java b/app/src/main/java/at/bitfire/davdroid/ui/setup/DavResourceFinder.java index 462edcbd..7c9f45eb 100644 --- a/app/src/main/java/at/bitfire/davdroid/ui/setup/DavResourceFinder.java +++ b/app/src/main/java/at/bitfire/davdroid/ui/setup/DavResourceFinder.java @@ -312,7 +312,7 @@ public class DavResourceFinder { if (principal != null) return principal; - } catch(NotFoundException e) { + } catch(NotFoundException|IllegalArgumentException e) { log.log(Level.WARNING, "No resource found", e); } return null;