From 534953fe4c4f0efe091135f3b0b077f758686a9d Mon Sep 17 00:00:00 2001 From: Ricki Hirner Date: Sun, 14 Jun 2015 12:00:34 +0200 Subject: [PATCH] Check for null values in StructuredPostal.TYPE (should fix #549) --- .../davdroid/resource/LocalAddressBook.java | 33 ++++++++++--------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/at/bitfire/davdroid/resource/LocalAddressBook.java b/app/src/main/java/at/bitfire/davdroid/resource/LocalAddressBook.java index e79931fe..541f2783 100644 --- a/app/src/main/java/at/bitfire/davdroid/resource/LocalAddressBook.java +++ b/app/src/main/java/at/bitfire/davdroid/resource/LocalAddressBook.java @@ -142,7 +142,7 @@ public class LocalAddressBook extends LocalCollection { String where; if (remoteResources.length != 0) { - List sqlFileNames = new LinkedList(); + List sqlFileNames = new LinkedList<>(); for (Resource res : remoteResources) sqlFileNames.add(DatabaseUtils.sqlEscapeString(res.getName())); where = entryColumnRemoteName() + " NOT IN (" + StringUtils.join(sqlFileNames, ",") + ")"; @@ -472,19 +472,20 @@ public class LocalAddressBook extends LocalCollection { protected void populatePostalAddress(Contact c, ContentValues row) { Address address = new Address(); address.setLabel(row.getAsString(StructuredPostal.FORMATTED_ADDRESS)); - switch (row.getAsInteger(StructuredPostal.TYPE)) { - case StructuredPostal.TYPE_HOME: - address.addType(AddressType.HOME); - break; - case StructuredPostal.TYPE_WORK: - address.addType(AddressType.WORK); - break; - case StructuredPostal.TYPE_CUSTOM: - String customType = row.getAsString(StructuredPostal.LABEL); - if (StringUtils.isNotEmpty(customType)) - address.addType(AddressType.get(labelToXName(customType))); - break; - } + if (row.containsKey(StructuredPostal.TYPE)) + switch (row.getAsInteger(StructuredPostal.TYPE)) { + case StructuredPostal.TYPE_HOME: + address.addType(AddressType.HOME); + break; + case StructuredPostal.TYPE_WORK: + address.addType(AddressType.WORK); + break; + case StructuredPostal.TYPE_CUSTOM: + String customType = row.getAsString(StructuredPostal.LABEL); + if (StringUtils.isNotEmpty(customType)) + address.addType(AddressType.get(labelToXName(customType))); + break; + } address.setStreetAddress(row.getAsString(StructuredPostal.STREET)); address.setPoBox(row.getAsString(StructuredPostal.POBOX)); address.setExtendedAddress(row.getAsString(StructuredPostal.NEIGHBORHOOD)); @@ -965,7 +966,7 @@ public class LocalAddressBook extends LocalCollection { String lineStreet = StringUtils.join(new String[] { address.getStreetAddress(), address.getPoBox(), address.getExtendedAddress() }, " "), lineLocality = StringUtils.join(new String[] { address.getPostalCode(), address.getLocality() }, " "); - List lines = new LinkedList(); + List lines = new LinkedList<>(); if (lineStreet != null) lines.add(lineStreet); if (address.getRegion() != null && !address.getRegion().isEmpty()) @@ -1031,7 +1032,7 @@ public class LocalAddressBook extends LocalCollection { } protected Builder buildRelated(Builder builder, RelatedType type, String name) { - int typeCode = 0; + int typeCode; String typeLabel = null; if (type == RelatedType.CHILD) typeCode = Relation.TYPE_CHILD;