1
0
mirror of https://github.com/etesync/android synced 2024-12-23 15:18:14 +00:00

Minor optimizations

* catch IllegalArgumentException from HttpUrl in DavResourceFinder (caused crash when logging in with email "test@server/withslash")
* use IteratorChain in DavService collection enumeration
This commit is contained in:
Ricki Hirner 2016-04-19 21:56:05 +02:00
parent fb0552de46
commit 7997606550
3 changed files with 11 additions and 7 deletions

View File

@ -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'

View File

@ -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<HttpUrl> iterator = homeSets.iterator(); iterator.hasNext(); ) {
HttpUrl homeSet = iterator.next();
for (Iterator<HttpUrl> 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<DavResource> selfAndMembers = new HashSet<>(dav.members);
selfAndMembers.add(dav);
for (DavResource member : selfAndMembers) {
IteratorChain<DavResource> 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();
}
}

View File

@ -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;