[folks] core: Nullability fixes



commit d3385bae363651fe9588826210f79359fa820e01
Author: Philip Withnall <philip tecnocode co uk>
Date:   Wed Dec 21 23:58:39 2011 +0000

    core: Nullability fixes
    
    Almost all of these are just the necessary â(!)â annotations to allow the
    nullability check to pass. There were few, if any, actual bugs found by the
    check (which either means folks is perfect, or Vala's nullability checking
    is imperfect).
    
    This brings us down from 296 nullability errors to just below 50.
    
    The work was done by compiling folks with valacâs
    --enable-experimental-non-null flag. Weâre not ready to add the flag to
    VALAFLAGS permanently yet, since this commit depends on various annotation
    fixes in GLib (and similarly, the next one depends on several in EDS).
    However, the fixes themselves should be valid without the flag.
    
    This depends on (at least):
     â https://bugzilla.gnome.org/show_bug.cgi?id=666700
     â https://bugzilla.gnome.org/show_bug.cgi?id=666699

 folks/abstract-field-details.vala |    4 +-
 folks/avatar-cache.vala           |   17 ++-
 folks/backend-store.vala          |   80 ++++++++++------
 folks/debug.vala                  |   23 +++--
 folks/email-details.vala          |    4 +-
 folks/im-details.vala             |   28 +++---
 folks/individual-aggregator.vala  |  169 +++++++++++++++++++--------------
 folks/individual.vala             |  190 +++++++++++++++++++++---------------
 folks/note-details.vala           |   12 +--
 folks/object-cache.vala           |   43 +++++----
 folks/persona-store.vala          |    9 +-
 folks/persona.vala                |    6 +-
 folks/phone-details.vala          |    7 +-
 folks/postal-address-details.vala |    2 +-
 folks/potential-match.vala        |   14 ++-
 folks/role-details.vala           |    7 +-
 folks/url-details.vala            |    2 +-
 folks/web-service-details.vala    |    2 +-
 18 files changed, 357 insertions(+), 262 deletions(-)
---
diff --git a/folks/abstract-field-details.vala b/folks/abstract-field-details.vala
index a0819af..91281e4 100644
--- a/folks/abstract-field-details.vala
+++ b/folks/abstract-field-details.vala
@@ -271,8 +271,8 @@ public abstract class Folks.AbstractFieldDetails<T> : Object
   public virtual bool equal (AbstractFieldDetails<T> that)
     {
       return (this.get_type () == that.get_type ()) &&
-        this.values_equal<T> (that) &&
-        this.parameters_equal<T> (that);
+        this.values_equal (that) &&
+        this.parameters_equal (that);
     }
 
   /**
diff --git a/folks/avatar-cache.vala b/folks/avatar-cache.vala
index 3dc0e39..d03b74a 100644
--- a/folks/avatar-cache.vala
+++ b/folks/avatar-cache.vala
@@ -29,7 +29,7 @@ using GLib;
  */
 public class Folks.AvatarCache : Object
 {
-  private static weak AvatarCache _instance = null; /* needs to be locked */
+  private static weak AvatarCache? _instance = null; /* needs to be locked */
   private File _cache_directory;
 
   /**
@@ -64,14 +64,19 @@ public class Folks.AvatarCache : Object
     {
       lock (AvatarCache._instance)
         {
-          var retval = AvatarCache._instance;
+          var _retval = AvatarCache._instance;
+          AvatarCache retval;
 
-          if (retval == null)
+          if (_retval == null)
             {
               /* use an intermediate variable to force a strong reference */
               retval = new AvatarCache ();
               AvatarCache._instance = retval;
             }
+          else
+            {
+              retval = (!) _retval;
+            }
 
           return retval;
         }
@@ -143,9 +148,9 @@ public class Folks.AvatarCache : Object
               dest_avatar_stream =
                   yield dest_avatar_file.replace_async (null, false,
                       FileCreateFlags.PRIVATE);
-              yield dest_avatar_stream.splice_async (src_avatar_stream,
+              yield ((!) dest_avatar_stream).splice_async (src_avatar_stream,
                   OutputStreamSpliceFlags.NONE);
-              yield dest_avatar_stream.close_async ();
+              yield ((!) dest_avatar_stream).close_async ();
 
               break;
             }
@@ -161,7 +166,7 @@ public class Folks.AvatarCache : Object
 
               if (dest_avatar_stream != null)
                 {
-                  yield dest_avatar_stream.close_async ();
+                  yield ((!) dest_avatar_stream).close_async ();
                 }
 
               throw e;
diff --git a/folks/backend-store.vala b/folks/backend-store.vala
index 9832bd4..a00bf19 100644
--- a/folks/backend-store.vala
+++ b/folks/backend-store.vala
@@ -48,7 +48,7 @@ public class Folks.BackendStore : Object {
   private File _config_file;
   private GLib.KeyFile _backends_key_file;
   private HashMap<string,unowned Module> _modules;
-  private static weak BackendStore _instance;
+  private static weak BackendStore? _instance = null;
   private bool _is_prepared = false;
   private Debug _debug;
 
@@ -116,16 +116,16 @@ public class Folks.BackendStore : Object {
    */
   public static BackendStore dup ()
     {
-      if (_instance == null)
+      if (BackendStore._instance == null)
         {
           /* use an intermediate variable to force a strong reference */
           var new_instance = new BackendStore ();
-          _instance = new_instance;
+          BackendStore._instance = new_instance;
 
           return new_instance;
         }
 
-      return _instance;
+      return (!) BackendStore._instance;
     }
 
   private BackendStore ()
@@ -168,10 +168,9 @@ public class Folks.BackendStore : Object {
 
       /* Disconnect from the debug handler */
       this._debug.print_status.disconnect (this._debug_print_status);
-      this._debug = null;
 
       /* manually clear the singleton instance */
-      _instance = null;
+      BackendStore._instance = null;
     }
 
   private void _debug_print_status (Debug debug)
@@ -201,7 +200,7 @@ public class Folks.BackendStore : Object {
 
           foreach (var persona_store in backend.persona_stores.values)
             {
-              string trust_level = null;
+              string? trust_level = null;
 
               switch (persona_store.trust_level)
                 {
@@ -284,8 +283,10 @@ public class Folks.BackendStore : Object {
           yield this._backend_unload_if_needed (backend_existing);
         }
 
-      var path = Environment.get_variable ("FOLKS_BACKEND_PATH");
-      if (path == null)
+      string? _path = Environment.get_variable ("FOLKS_BACKEND_PATH");
+      string path;
+
+      if (_path == null)
         {
           path = BuildConf.BACKEND_DIR;
 
@@ -294,16 +295,17 @@ public class Folks.BackendStore : Object {
         }
       else
         {
+          path = (!) _path;
+
           debug ("Using environment variable FOLKS_BACKEND_PATH = " +
               "'%s' to look for backends", path);
         }
 
-      var modules = new HashMap<string, File?> ();
+      var modules = new HashMap<string, File> ();
       var path_split = path.split (":");
       foreach (unowned string subpath in path_split)
         {
           var file = File.new_for_path (subpath);
-          assert (file != null);
 
           bool is_file;
           bool is_dir;
@@ -315,8 +317,13 @@ public class Folks.BackendStore : Object {
           else if (is_dir)
             {
               var cur_modules = yield this._get_modules_from_dir (file);
-              foreach (var entry in cur_modules.entries)
-                modules.set (entry.key, entry.value);
+              if (cur_modules != null)
+                {
+                  foreach (var entry in ((!) cur_modules).entries)
+                    {
+                      modules.set (entry.key, entry.value);
+                    }
+                }
             }
           else
             {
@@ -369,12 +376,12 @@ public class Folks.BackendStore : Object {
 
       if (!this._backend_is_enabled (backend.name))
         {
-          var backend_existing = this._backend_hash.get (backend.name);
+          Backend? backend_existing = this._backend_hash.get (backend.name);
           if (backend_existing != null)
             {
               try
                 {
-                  yield backend_existing.unprepare ();
+                  yield ((!) backend_existing).unprepare ();
                 }
               catch (GLib.Error e)
                 {
@@ -382,7 +389,7 @@ public class Folks.BackendStore : Object {
                       e.message);
                 }
 
-              this._prepared_backends.unset (backend_existing.name);
+              this._prepared_backends.unset (((!) backend_existing).name);
 
               unloaded = true;
             }
@@ -399,11 +406,11 @@ public class Folks.BackendStore : Object {
   public void add_backend (Backend backend)
     {
       /* Purge any other backend with the same name; re-add if enabled */
-      var backend_existing = this._backend_hash.get (backend.name);
+      Backend? backend_existing = this._backend_hash.get (backend.name);
       if (backend_existing != null && backend_existing != backend)
         {
-          backend_existing.unprepare ();
-          this._prepared_backends.unset (backend_existing.name);
+          ((!) backend_existing).unprepare ();
+          this._prepared_backends.unset (((!) backend_existing).name);
         }
 
       this._debug._register_domain (backend.name);
@@ -566,17 +573,26 @@ public class Folks.BackendStore : Object {
            * aliases */
           var is_symlink = info.get_is_symlink ();
 
-          string mime = ContentType.get_mime_type (content_type);
+          string? mime = ContentType.get_mime_type (content_type);
 
           if (file_type == FileType.DIRECTORY)
             {
               var modules = yield this._get_modules_from_dir (file);
-              foreach (var entry in modules.entries)
-                modules_final.set (entry.key, entry.value);
+              if (modules != null)
+                {
+                  foreach (var entry in ((!) modules).entries)
+                    {
+                      modules_final.set (entry.key, entry.value);
+                    }
+                }
             }
           else if (mime == "application/x-sharedlib" && !is_symlink)
             {
-              modules_final.set (file.get_path (), file);
+              var path = file.get_path ();
+              if (path != null)
+                {
+                  modules_final.set ((!) path, file);
+                }
             }
           else if (mime == null)
             {
@@ -595,13 +611,18 @@ public class Folks.BackendStore : Object {
 
   private void _load_module_from_file (File file)
     {
-      var file_path = file.get_path ();
+      var _file_path = file.get_path ();
+      if (_file_path == null)
+        {
+          return;
+        }
+      var file_path = (!) _file_path;
 
       if (this._modules.has_key (file_path))
         return;
 
-      Module module = Module.open (file_path, ModuleFlags.BIND_LOCAL);
-      if (module == null)
+      var _module = Module.open (file_path, ModuleFlags.BIND_LOCAL);
+      if (_module == null)
         {
           /* Translators: the first parameter is a filename and the second is an
            * error message. */
@@ -610,6 +631,7 @@ public class Folks.BackendStore : Object {
 
           return;
         }
+      unowned Module module = (!) _module;
 
       void* function;
 
@@ -681,7 +703,7 @@ public class Folks.BackendStore : Object {
   private async void _load_disabled_backend_names ()
     {
       File file;
-      unowned string path = Environment.get_variable (
+      unowned string? path = Environment.get_variable (
           "FOLKS_BACKEND_STORE_KEY_FILE_PATH");
       if (path == null)
         {
@@ -695,10 +717,10 @@ public class Folks.BackendStore : Object {
         }
       else
         {
-          file = File.new_for_path (path);
+          file = File.new_for_path ((!) path);
           debug ("Using environment variable " +
               "FOLKS_BACKEND_STORE_KEY_FILE_PATH = '%s' to load the backends " +
-              "key file.", path);
+              "key file.", (!) path);
         }
 
       this._config_file = file;
diff --git a/folks/debug.vala b/folks/debug.vala
index 060401a..233af2f 100644
--- a/folks/debug.vala
+++ b/folks/debug.vala
@@ -48,7 +48,8 @@ public class Folks.Debug : Object
     KEY_FILE_BACKEND = 1 << 2
   }
 
-  private static weak Debug _instance; /* needs to be locked when accessed */
+  /* Needs to be locked when accessed: */
+  private static weak Debug? _instance = null;
   private HashSet<string> _domains; /* needs to be locked when accessed */
   private bool _all = false; /* needs _domains to be locked when accessed */
 
@@ -196,14 +197,19 @@ public class Folks.Debug : Object
     {
       lock (Debug._instance)
         {
-          var retval = Debug._instance;
+          Debug? _retval = Debug._instance;
+          Debug retval;
 
-          if (retval == null)
+          if (_retval == null)
             {
               /* use an intermediate variable to force a strong reference */
               retval = new Debug ();
               Debug._instance = retval;
             }
+          else
+            {
+              retval = (!) _retval;
+            }
 
           return retval;
         }
@@ -234,7 +240,7 @@ public class Folks.Debug : Object
 
           if (debug_flags != null && debug_flags != "")
             {
-              var domains_split = debug_flags.split (",");
+              var domains_split = ((!) debug_flags).split (",");
               foreach (var domain in domains_split)
                 {
                   var domain_lower = domain.down ();
@@ -283,7 +289,7 @@ public class Folks.Debug : Object
     }
 
   private void _set_handler (
-      string? domain,
+      string domain,
       LogLevelFlags flags,
       LogFunc log_func)
     {
@@ -429,7 +435,7 @@ public class Folks.Debug : Object
           return "(null)";
         }
 
-      return input;
+      return (!) input;
     }
 
   struct KeyValuePair
@@ -465,11 +471,12 @@ public class Folks.Debug : Object
        * purposes */
       while (true)
         {
-          string? key = valist.arg ();
-          if (key == null)
+          string? _key = valist.arg ();
+          if (_key == null)
             {
               break;
             }
+          var key = (!) _key;
 
           string? val = valist.arg ();
 
diff --git a/folks/email-details.vala b/folks/email-details.vala
index 4ed3e15..141025c 100644
--- a/folks/email-details.vala
+++ b/folks/email-details.vala
@@ -57,7 +57,7 @@ public class Folks.EmailFieldDetails : AbstractFieldDetails<string>
 
       this.value = value;
       if (parameters != null)
-        this.parameters = parameters;
+        this.parameters = (!) parameters;
     }
 
   /**
@@ -67,7 +67,7 @@ public class Folks.EmailFieldDetails : AbstractFieldDetails<string>
    */
   public override bool equal (AbstractFieldDetails<string> that)
     {
-      return base.equal<string> (that);
+      return base.equal (that);
     }
 
   /**
diff --git a/folks/im-details.vala b/folks/im-details.vala
index 66becd5..f891e36 100644
--- a/folks/im-details.vala
+++ b/folks/im-details.vala
@@ -66,7 +66,7 @@ public class Folks.ImFieldDetails : AbstractFieldDetails<string>
 
       this.value = value;
       if (parameters != null)
-        this.parameters = parameters;
+        this.parameters = (!) parameters;
     }
 
   /**
@@ -76,7 +76,7 @@ public class Folks.ImFieldDetails : AbstractFieldDetails<string>
    */
   public override bool equal (AbstractFieldDetails<string> that)
     {
-      return base.equal<string> (that);
+      return base.equal (that);
     }
 
   /**
@@ -179,7 +179,7 @@ public interface Folks.ImDetails : Object
                   im_address);
             }
 
-          string resource = null;
+          string? resource = null;
           if (parts.length == 2)
             resource = parts[1];
 
@@ -193,20 +193,20 @@ public interface Folks.ImDetails : Object
                   im_address);
             }
 
-          string node, domain;
+          string? node, _domain;
           if (parts.length == 2)
             {
               node = parts[0];
-              domain = parts[1];
+              _domain = parts[1];
             }
           else
             {
               node = null;
-              domain = parts[0];
+              _domain = parts[0];
             }
 
           if ((node != null && node == "") ||
-              (domain == null || domain == "") ||
+              (_domain == null || _domain == "") ||
               (resource != null && resource == ""))
             {
               throw new ImDetailsError.INVALID_IM_ADDRESS (
@@ -215,24 +215,24 @@ public interface Folks.ImDetails : Object
                   im_address);
             }
 
-          domain = domain.down ();
+          string domain = ((!) _domain).down ();
           if (node != null)
-            node = node.down ();
+            node = ((!) node).down ();
 
           /* Build a new JID */
-          string normalised = null;
+          string? normalised = null;
 
           if (node != null && resource != null)
             {
-              normalised = "%s %s/%s".printf (node, domain, resource);
+              normalised = "%s %s/%s".printf ((!) node, domain, (!) resource);
             }
           else if (node != null)
             {
-              normalised = "%s %s".printf (node, domain);
+              normalised = "%s %s".printf ((!) node, domain);
             }
           else if (resource != null)
             {
-              normalised = "%s/%s".printf (domain, resource);
+              normalised = "%s/%s".printf (domain, (!) resource);
             }
           else
             {
@@ -242,7 +242,7 @@ public interface Folks.ImDetails : Object
                   im_address);
             }
 
-          return normalised.normalize (-1, NormalizeMode.NFKC);
+          return ((!) normalised).normalize (-1, NormalizeMode.NFKC);
         }
       else
         {
diff --git a/folks/individual-aggregator.vala b/folks/individual-aggregator.vala
index 0d71384..6c3cd51 100644
--- a/folks/individual-aggregator.vala
+++ b/folks/individual-aggregator.vala
@@ -185,7 +185,7 @@ public class Folks.IndividualAggregator : Object
    *
    * @since 0.3.0
    */
-  public Individual user { get; private set; }
+  public Individual? user { get; private set; }
 
   /**
    * Emitted when one or more { link Individual}s are added to or removed from
@@ -303,7 +303,7 @@ public class Folks.IndividualAggregator : Object
       if (store_config_ids != null)
         {
           debug ("Setting primary store IDs from environment variable.");
-          this._configure_primary_store (store_config_ids);
+          this._configure_primary_store ((!) store_config_ids);
         }
       else
         {
@@ -325,8 +325,13 @@ public class Folks.IndividualAggregator : Object
               GConf.Value? val = client.get (this._FOLKS_CONFIG_KEY);
               if (val != null)
                 {
-                  debug ("Setting primary store IDs from GConf.");
-                  this._configure_primary_store (val.get_string ());
+                  string? val_str = ((!) val).get_string ();
+
+                  if (val_str != null)
+                    {
+                      debug ("Setting primary store IDs from GConf.");
+                      this._configure_primary_store ((!) val_str);
+                    }
                 }
             }
           catch (GLib.Error e)
@@ -341,7 +346,7 @@ public class Folks.IndividualAggregator : Object
 
       var disable_linking = Environment.get_variable ("FOLKS_DISABLE_LINKING");
       if (disable_linking != null)
-        disable_linking = disable_linking.strip ().down ();
+        disable_linking = ((!) disable_linking).strip ().down ();
       this._linking_enabled = (disable_linking == null ||
           disable_linking == "no" || disable_linking == "0");
 
@@ -354,7 +359,6 @@ public class Folks.IndividualAggregator : Object
     {
       this._backend_store.backend_available.disconnect (
           this._backend_available_cb);
-      this._backend_store = null;
 
       this._debug.print_status.disconnect (this._debug_print_status);
     }
@@ -403,7 +407,7 @@ public class Folks.IndividualAggregator : Object
 
       foreach (var individual in this.individuals.values)
         {
-          string trust_level = null;
+          string? trust_level = null;
 
           switch (individual.trust_level)
             {
@@ -569,22 +573,34 @@ public class Folks.IndividualAggregator : Object
       for (var i = 0; i < individuals.length; i++)
         {
           var a = individuals[i];
-          var matches_a = matches.get (a);
-          if (matches_a == null)
+
+          HashMap<Individual, MatchResult>? _matches_a = matches.get (a);
+          HashMap<Individual, MatchResult> matches_a;
+          if (_matches_a == null)
             {
               matches_a = new HashMap<Individual, MatchResult> ();
               matches.set (a, matches_a);
             }
+          else
+            {
+              matches_a = (!) _matches_a;
+            }
 
           for (var f = i + 1; f < individuals.length; f++)
             {
               var b = individuals[f];
-              var matches_b = matches.get (b);
-              if (matches_b == null)
+
+              HashMap<Individual, MatchResult>? _matches_b = matches.get (b);
+              HashMap<Individual, MatchResult> matches_b;
+              if (_matches_b == null)
                 {
                   matches_b = new HashMap<Individual, MatchResult> ();
                   matches.set (b, matches_b);
                 }
+              else
+                {
+                  matches_b = (!) _matches_b;
+                }
 
               var result = matchObj.potential_match (a, b);
 
@@ -664,16 +680,16 @@ public class Folks.IndividualAggregator : Object
               var previous_store = this._primary_store;
               this._primary_store = store;
 
-              this._primary_store.freeze_notify ();
+              store.freeze_notify ();
               if (previous_store != null)
                 {
-                  previous_store.freeze_notify ();
-                  previous_store.is_primary_store = false;
+                  ((!) previous_store).freeze_notify ();
+                  ((!) previous_store).is_primary_store = false;
                 }
-              this._primary_store.is_primary_store = true;
+              store.is_primary_store = true;
               if (previous_store != null)
-                previous_store.thaw_notify ();
-              this._primary_store.thaw_notify ();
+                ((!) previous_store).thaw_notify ();
+              store.thaw_notify ();
 
               this.notify_property ("primary-store");
             }
@@ -771,26 +787,26 @@ public class Folks.IndividualAggregator : Object
       Persona? actor = null,
       GroupDetails.ChangeReason reason = GroupDetails.ChangeReason.NONE)
     {
-      var _added = added;
-      var _removed = removed;
-      var _changes = changes;
+      Set<Individual> _added;
+      Set<Individual> _removed;
+      MultiMap<Individual?, Individual?> _changes;
 
-      if ((added == null || added.size == 0) &&
-          (removed == null || removed.size == 0) &&
-          (changes == null || changes.size == 0))
+      if ((added == null || ((!) added).size == 0) &&
+          (removed == null || ((!) removed).size == 0) &&
+          (changes == null || ((!) changes).size == 0))
         {
           /* Don't bother emitting it if nothing's changed */
           return;
         }
-      else if (added == null)
-        {
-          _added = new HashSet<Individual> ();
-        }
-      else if (removed == null)
+
+      _added = (added != null) ? (!) added : new HashSet<Individual> ();
+      _removed = (removed != null) ? (!) removed : new HashSet<Individual> ();
+
+      if (changes != null)
         {
-          _removed = new HashSet<Individual> ();
+          _changes = (!) changes;
         }
-      else if (changes == null)
+      else
         {
           _changes = new HashMultiMap<Individual?, Individual?> ();
         }
@@ -806,14 +822,15 @@ public class Folks.IndividualAggregator : Object
               foreach (var added_ind in _changes.get (removed_ind))
                 {
                   debug ("    %s (%p) â %s (%p)",
-                      (removed_ind != null) ? removed_ind.id : "", removed_ind,
-                      (added_ind != null) ? added_ind.id : "", added_ind);
+                      (removed_ind != null) ? ((!) removed_ind).id : "",
+                      removed_ind,
+                      (added_ind != null) ? ((!) added_ind).id : "", added_ind);
 
                   if (removed_ind != null)
                     {
                       debug ("      Removed individual's personas:");
 
-                      foreach (var p in removed_ind.personas)
+                      foreach (var p in ((!) removed_ind).personas)
                         {
                           debug ("        %s (%p)", p.uid, p);
                         }
@@ -823,7 +840,7 @@ public class Folks.IndividualAggregator : Object
                     {
                       debug ("      Added individual's personas:");
 
-                      foreach (var p in added_ind.personas)
+                      foreach (var p in ((!) added_ind).personas)
                         {
                           debug ("        %s (%p)", p.uid, p);
                         }
@@ -849,7 +866,7 @@ public class Folks.IndividualAggregator : Object
       individual.removed.disconnect (this._individual_removed_cb);
     }
 
-  private void _add_personas (Set<Persona> added, ref Individual user,
+  private void _add_personas (Set<Persona> added, ref Individual? user,
       ref HashMultiMap<Individual?, Individual?> individuals_changes)
     {
       foreach (var persona in added)
@@ -867,7 +884,6 @@ public class Folks.IndividualAggregator : Object
           HashSet<Individual> candidate_inds = new HashSet<Individual> ();
 
           var final_personas = new HashSet<Persona> ();
-          Individual final_individual = null;
 
           debug ("Aggregating persona '%s' on '%s'.", persona.uid, persona.iid);
 
@@ -875,22 +891,23 @@ public class Folks.IndividualAggregator : Object
            * existing this.user. */
           if (persona.is_user == true && user != null)
             {
-              debug ("    Found candidate individual '%s' as user.", user.id);
-              candidate_inds.add (user);
+              debug ("    Found candidate individual '%s' as user.",
+                  ((!) user).id);
+              candidate_inds.add ((!) user);
             }
 
           /* If we don't trust the PersonaStore at all, we can't link the
            * Persona to any existing Individual */
           if (trust_level != PersonaStoreTrust.NONE)
             {
-              var candidate_ind = this._link_map.lookup (persona.iid);
+              Individual? candidate_ind = this._link_map.lookup (persona.iid);
               if (candidate_ind != null &&
-                  candidate_ind.trust_level != TrustLevel.NONE &&
-                  !candidate_inds.contains (candidate_ind))
+                  ((!) candidate_ind).trust_level != TrustLevel.NONE &&
+                  !candidate_inds.contains ((!) candidate_ind))
                 {
                   debug ("    Found candidate individual '%s' by IID '%s'.",
-                      candidate_ind.id, persona.iid);
-                  candidate_inds.add (candidate_ind);
+                      ((!) candidate_ind).id, persona.iid);
+                  candidate_inds.add ((!) candidate_ind);
                 }
             }
 
@@ -919,17 +936,18 @@ public class Folks.IndividualAggregator : Object
                   persona.linkable_property_to_links (prop_name, (l) =>
                     {
                       unowned string prop_linking_value = l;
-                      var candidate_ind =
+                      Individual? candidate_ind =
                           this._link_map.lookup (prop_linking_value);
 
                       if (candidate_ind != null &&
-                          candidate_ind.trust_level != TrustLevel.NONE &&
-                          !candidate_inds.contains (candidate_ind))
+                          ((!) candidate_ind).trust_level != TrustLevel.NONE &&
+                          !candidate_inds.contains ((!) candidate_ind))
                         {
                           debug ("    Found candidate individual '%s' by " +
                               "linkable property '%s' = '%s'.",
-                              candidate_ind.id, prop_name, prop_linking_value);
-                          candidate_inds.add (candidate_ind);
+                              ((!) candidate_ind).id, prop_name,
+                              prop_linking_value);
+                          candidate_inds.add ((!) candidate_ind);
                         }
                     });
                 }
@@ -960,7 +978,7 @@ public class Folks.IndividualAggregator : Object
             }
 
           /* Create the final linked Individual */
-          final_individual = new Individual (final_personas);
+          var final_individual = new Individual (final_personas);
           debug ("    Created new individual '%s' (%p) with personas:",
               final_individual.id, final_individual);
           foreach (var p in final_personas)
@@ -976,7 +994,7 @@ public class Folks.IndividualAggregator : Object
               /* Transitively update the individuals_changes. We have to do this
                * in two stages as we can't modify individuals_changes while
                * iterating over it. */
-              var transitive_updates = new HashSet<Individual> ();
+              var transitive_updates = new HashSet<Individual?> ();
 
               foreach (var k in individuals_changes.get_keys ())
                 {
@@ -1033,7 +1051,7 @@ public class Folks.IndividualAggregator : Object
        * changed, so that persona might require re-linking. We do this in a
        * simplistic and hacky way (which should work) by simply treating the
        * persona as if it's been removed and re-added. */
-      var persona = obj as Persona;
+      var persona = (!) (obj as Persona);
 
       debug ("Linkable property '%s' changed for persona '%s' " +
           "(is user: %s, IID: %s).", pspec.name, persona.uid,
@@ -1162,10 +1180,10 @@ public class Folks.IndividualAggregator : Object
           /* Find the Individual containing the Persona (if any) and mark them
            * for removal (any other Personas they have which aren't being
            * removed will be re-linked into other Individuals). */
-          var ind = this._link_map.lookup (persona.iid);
+          Individual? ind = this._link_map.lookup (persona.iid);
           if (ind != null)
             {
-              removed_individuals.add (ind);
+              removed_individuals.add ((!) ind);
             }
 
           /* Stop listening to notifications about the persona's linkable
@@ -1279,18 +1297,18 @@ public class Folks.IndividualAggregator : Object
 
                   if (old_ind != null)
                     {
-                      removed_individuals.add (old_ind);
+                      removed_individuals.add ((!) old_ind);
                     }
 
                   if (new_ind != null)
                     {
-                      added_individuals.add (new_ind);
-                      this._connect_to_individual (new_ind);
+                      added_individuals.add ((!) new_ind);
+                      this._connect_to_individual ((!) new_ind);
                     }
 
                   if (old_ind != null && new_ind != null)
                     {
-                      replaced_individuals.set (old_ind, new_ind);
+                      replaced_individuals.set ((!) old_ind, (!) new_ind);
                     }
                 }
             }
@@ -1309,7 +1327,7 @@ public class Folks.IndividualAggregator : Object
           var new_ind = iter.get_value ();
 
           debug ("    %s (%p) â %s (%p)", old_ind.id, old_ind,
-              (new_ind != null) ? new_ind.id : "", new_ind);
+              new_ind.id, new_ind);
 
           old_ind.replace (new_ind);
         }
@@ -1438,7 +1456,7 @@ public class Folks.IndividualAggregator : Object
       if (replacement != null)
         {
           debug ("Individual '%s' removed (replaced by '%s')", i.id,
-              replacement.id);
+              ((!) replacement).id);
         }
       else
         {
@@ -1493,7 +1511,7 @@ public class Folks.IndividualAggregator : Object
       PersonaStore persona_store,
       HashTable<string, Value?> details) throws IndividualAggregatorError
     {
-      Persona persona = null;
+      Persona? persona = null;
       try
         {
           var details_copy = this._asv_copy (details);
@@ -1520,7 +1538,7 @@ public class Folks.IndividualAggregator : Object
 
       if (parent != null && persona != null)
         {
-          parent.personas.add (persona);
+          ((!) parent).personas.add ((!) persona);
         }
 
       return persona;
@@ -1614,7 +1632,7 @@ public class Folks.IndividualAggregator : Object
 
       /* Create a new persona in the primary store which links together the
        * given personas */
-      assert (this._primary_store.type_id ==
+      assert (((!) this._primary_store).type_id ==
           this._configured_primary_store_type_id);
 
       /* `protocols_addrs_set` will be passed to the new Kf.Persona */
@@ -1680,7 +1698,8 @@ public class Folks.IndividualAggregator : Object
         {
           var im_addresses_value = Value (typeof (MultiMap));
           im_addresses_value.set_object (protocols_addrs_set);
-          details.insert (PersonaStore.detail_key (PersonaDetail.IM_ADDRESSES),
+          details.insert (
+              (!) PersonaStore.detail_key (PersonaDetail.IM_ADDRESSES),
               im_addresses_value);
         }
 
@@ -1688,8 +1707,8 @@ public class Folks.IndividualAggregator : Object
         {
           var web_service_addresses_value = Value (typeof (MultiMap));
           web_service_addresses_value.set_object (web_service_addrs_set);
-          details.insert (PersonaStore.detail_key
-              (PersonaDetail.WEB_SERVICE_ADDRESSES),
+          details.insert (
+              (!) PersonaStore.detail_key (PersonaDetail.WEB_SERVICE_ADDRESSES),
               web_service_addresses_value);
         }
 
@@ -1698,12 +1717,12 @@ public class Folks.IndividualAggregator : Object
           var local_ids_value = Value (typeof (Set<string>));
           local_ids_value.set_object (local_ids);
           details.insert (
-              Folks.PersonaStore.detail_key (PersonaDetail.LOCAL_IDS),
+              (!) Folks.PersonaStore.detail_key (PersonaDetail.LOCAL_IDS),
               local_ids_value);
         }
 
       yield this.add_persona_from_details (null,
-          this._primary_store, details);
+          (!) this._primary_store, details);
     }
 
   /**
@@ -1750,11 +1769,13 @@ public class Folks.IndividualAggregator : Object
 
       foreach (var persona in personas)
         {
+          /* Since persona.store != null, we know that
+           * this._primary_store != null. */
           if (persona.store == this._primary_store)
             {
               debug ("    %s (is user: %s, IID: %s)", persona.uid,
                   persona.is_user ? "yes" : "no", persona.iid);
-              yield this._primary_store.remove_persona (persona);
+              yield ((!) this._primary_store).remove_persona (persona);
             }
         }
     }
@@ -1810,13 +1831,14 @@ public class Folks.IndividualAggregator : Object
       Persona? new_persona = null;
 
       if (this._primary_store != null &&
-          property_name in this._primary_store.always_writeable_properties)
+          property_name in
+              ((!) this._primary_store).always_writeable_properties)
         {
           try
             {
               debug ("    Using writeable store");
               new_persona = yield this.add_persona_from_details (null,
-                  this._primary_store, details);
+                  (!) this._primary_store, details);
             }
           catch (IndividualAggregatorError e1)
             {
@@ -1868,9 +1890,10 @@ public class Folks.IndividualAggregator : Object
               property_name);
         }
 
-      /* Link the persona to the existing individual */
+      /* Link the persona to the existing individual. We can guarantee
+       * new_persona != null because we'd have bailed out above otherwise. */
       var linking_personas = new HashSet<Persona> ();
-      linking_personas.add (new_persona);
+      linking_personas.add ((!) new_persona);
 
       foreach (var p2 in individual.personas)
         {
@@ -1881,6 +1904,6 @@ public class Folks.IndividualAggregator : Object
           property_name);
       yield this.link_personas (linking_personas);
 
-      return new_persona;
+      return (!) new_persona;
     }
 }
diff --git a/folks/individual.vala b/folks/individual.vala
index a101133..450e010 100644
--- a/folks/individual.vala
+++ b/folks/individual.vala
@@ -159,7 +159,7 @@ public class Folks.Individual : Object,
    */
   public async void change_avatar (LoadableIcon? avatar) throws PropertyError
     {
-      if ((this._avatar != null && this._avatar.equal (avatar)) ||
+      if ((this._avatar != null && ((!) this._avatar).equal (avatar)) ||
           (this._avatar == null && avatar == null))
         {
           return;
@@ -174,8 +174,14 @@ public class Folks.Individual : Object,
        * "avatar" property as writeable. */
       foreach (var p in this._persona_set)
         {
-          var a = p as AvatarDetails;
-          if (a != null && "avatar" in p.writeable_properties)
+          var _a = p as AvatarDetails;
+          if (_a == null)
+            {
+              continue;
+            }
+          var a = (!) _a;
+
+          if ("avatar" in p.writeable_properties)
             {
               try
                 {
@@ -310,8 +316,14 @@ public class Folks.Individual : Object,
        * as a writeable property. */
       foreach (var p in this._persona_set)
         {
-          var a = p as AliasDetails;
-          if (a != null && "alias" in p.writeable_properties)
+          var _a = p as AliasDetails;
+          if (_a == null)
+            {
+              continue;
+            }
+          var a = (!) _a;
+
+          if ("alias" in p.writeable_properties)
             {
               try
                 {
@@ -406,8 +418,14 @@ public class Folks.Individual : Object,
        * as a writeable property. */
       foreach (var p in this._persona_set)
         {
-          var n = p as NameDetails;
-          if (n != null && "nickname" in p.writeable_properties)
+          var _n = p as NameDetails;
+          if (_n == null)
+            {
+              continue;
+            }
+          var n = (!) _n;
+
+          if ("nickname" in p.writeable_properties)
             {
               try
                 {
@@ -621,8 +639,14 @@ public class Folks.Individual : Object,
        * is one property which is harmless to propagate. */
       foreach (var p in this._persona_set)
         {
-          var a = p as FavouriteDetails;
-          if (a != null && "is-favourite" in p.writeable_properties)
+          var _a = p as FavouriteDetails;
+          if (_a == null)
+            {
+              continue;
+            }
+          var a = (!) _a;
+
+          if ("is-favourite" in p.writeable_properties)
             {
               try
                 {
@@ -683,8 +707,14 @@ public class Folks.Individual : Object,
        * writeable property. */
       foreach (var p in this._persona_set)
         {
-          var g = p as GroupDetails;
-          if (g != null && "groups" in p.writeable_properties)
+          var _g = p as GroupDetails;
+          if (_g == null)
+            {
+              continue;
+            }
+          var g = (!) _g;
+
+          if ("groups" in p.writeable_properties)
             {
               try
                 {
@@ -923,7 +953,7 @@ public class Folks.Individual : Object,
   construct
     {
       debug ("Creating new Individual with %u Personas: %p",
-          (this.personas != null ? this.personas.size : 0), this);
+          this._persona_set.size, this);
 
       this._persona_set_ro = this._persona_set.read_only_view;
       this._urls_ro = this._urls.read_only_view;
@@ -950,8 +980,8 @@ public class Folks.Individual : Object,
       var _added = added;
       var _removed = removed;
 
-      if ((added == null || added.size == 0) &&
-          (removed == null || removed.size == 0))
+      if ((added == null || ((!) added).size == 0) &&
+          (removed == null || ((!) removed).size == 0))
         {
           /* Emitting it with no added or removed personas is pointless */
           return;
@@ -965,7 +995,9 @@ public class Folks.Individual : Object,
           _removed = new HashSet<Persona> ();
         }
 
-      this.personas_changed (_added.read_only_view, _removed.read_only_view);
+      // We've now guaranteed that both _added and _removed are non-null.
+      this.personas_changed (((!) _added).read_only_view,
+          ((!) _removed).read_only_view);
     }
 
   private void _store_removed_cb (PersonaStore store)
@@ -1136,7 +1168,7 @@ public class Folks.Individual : Object,
           if (p.get_type ().is_a (interface_type))
             {
               if (candidate_p == null ||
-                  primary_compare_func (p, candidate_p) > 0)
+                  primary_compare_func (p, (!) candidate_p) > 0)
                 {
                   candidate_p = p;
                 }
@@ -1205,11 +1237,11 @@ public class Folks.Individual : Object,
     {
       this._update_single_valued_property (typeof (PresenceDetails), (p) =>
         {
-          return (p as PresenceDetails).presence_type != PresenceType.UNSET;
+          return ((PresenceDetails) p).presence_type != PresenceType.UNSET;
         }, (a, b) =>
         {
-          var a_presence = (a as PresenceDetails).presence_type;
-          var b_presence = (b as PresenceDetails).presence_type;
+          var a_presence = ((PresenceDetails) a).presence_type;
+          var b_presence = ((PresenceDetails) b).presence_type;
 
           return PresenceDetails.typecmp (a_presence, b_presence);
         }, "presence", (p) =>
@@ -1220,9 +1252,9 @@ public class Folks.Individual : Object,
 
           if (p != null)
             {
-              presence_type = (p as PresenceDetails).presence_type;
-              presence_message = (p as PresenceDetails).presence_message;
-              presence_status = (p as PresenceDetails).presence_status;
+              presence_type = ((PresenceDetails) p).presence_type;
+              presence_message = ((PresenceDetails) p).presence_message;
+              presence_status = ((PresenceDetails) p).presence_status;
             }
 
           /* Only notify if any of the values have changed. */
@@ -1246,8 +1278,8 @@ public class Folks.Individual : Object,
           return true;
         }, (a, b) =>
         {
-          var a_is_favourite = (a as FavouriteDetails).is_favourite;
-          var b_is_favourite = (b as FavouriteDetails).is_favourite;
+          var a_is_favourite = ((FavouriteDetails) a).is_favourite;
+          var b_is_favourite = ((FavouriteDetails) b).is_favourite;
 
           return ((a_is_favourite == true) ? 1 : 0) -
                  ((b_is_favourite == true) ? 1 : 0);
@@ -1257,7 +1289,7 @@ public class Folks.Individual : Object,
 
           if (p != null)
             {
-              favourite = (p as FavouriteDetails).is_favourite;
+              favourite = ((FavouriteDetails) p).is_favourite;
             }
 
           /* Only notify if the value has changed. We have to set the private
@@ -1275,14 +1307,14 @@ public class Folks.Individual : Object,
     {
       this._update_single_valued_property (typeof (AliasDetails), (p) =>
         {
-          var alias = (p as AliasDetails).alias;
+          var alias = ((AliasDetails) p).alias;
           assert (alias != null);
 
           return (alias.strip () != ""); /* empty aliases are unset */
         }, (a, b) =>
         {
-          var a_alias = (a as AliasDetails).alias;
-          var b_alias = (b as AliasDetails).alias;
+          var a_alias = ((AliasDetails) a).alias;
+          var b_alias = ((AliasDetails) b).alias;
 
           assert (a_alias != null);
           assert (b_alias != null);
@@ -1305,7 +1337,7 @@ public class Folks.Individual : Object,
 
           if (p != null)
             {
-              alias = (p as AliasDetails).alias.strip ();
+              alias = ((AliasDetails) p).alias.strip ();
             }
 
           /* Only notify if the value has changed. We have to set the private
@@ -1324,7 +1356,7 @@ public class Folks.Individual : Object,
     {
       this._update_single_valued_property (typeof (AvatarDetails), (p) =>
         {
-          return (p as AvatarDetails).avatar != null;
+          return ((AvatarDetails) p).avatar != null;
         }, (a, b) =>
         {
           /* We can't compare two set avatars efficiently. See: bgo#652721. */
@@ -1335,13 +1367,13 @@ public class Folks.Individual : Object,
 
           if (p != null)
             {
-              avatar = (p as AvatarDetails).avatar;
+              avatar = ((AvatarDetails) p).avatar;
             }
 
           /* only notify if the value has changed */
           if ((this._avatar == null && avatar != null) ||
               (this._avatar != null &&
-               (avatar == null || !this._avatar.equal (avatar))))
+               (avatar == null || !((!) this._avatar).equal (avatar))))
             {
               this._avatar = avatar;
               this.notify_property ("avatar");
@@ -1456,8 +1488,8 @@ public class Folks.Individual : Object,
     {
       this._update_single_valued_property (typeof (NameDetails), (p) =>
         {
-          var name = (p as NameDetails).structured_name;
-          return (name != null && !name.is_empty ());
+          var name = ((NameDetails) p).structured_name;
+          return (name != null && !((!) name).is_empty ());
         }, (a, b) =>
         {
           /* Can't compare two set names. */
@@ -1468,9 +1500,9 @@ public class Folks.Individual : Object,
 
           if (p != null)
             {
-              name = (p as NameDetails).structured_name;
+              name = ((NameDetails) p).structured_name;
 
-              if (name != null && name.is_empty ())
+              if (name != null && ((!) name).is_empty ())
                 {
                   name = null;
                 }
@@ -1478,7 +1510,7 @@ public class Folks.Individual : Object,
 
           if ((this._structured_name == null && name != null) ||
               (this._structured_name != null &&
-               (name == null || !this._structured_name.equal (name))))
+               (name == null || !((!) this._structured_name).equal ((!) name))))
             {
               this._structured_name = name;
               this.notify_property ("structured-name");
@@ -1490,7 +1522,7 @@ public class Folks.Individual : Object,
     {
       this._update_single_valued_property (typeof (NameDetails), (p) =>
         {
-          var name = (p as NameDetails).full_name;
+          var name = ((NameDetails) p).full_name;
           assert (name != null);
 
           return (name.strip () != ""); /* empty names are unset */
@@ -1504,7 +1536,7 @@ public class Folks.Individual : Object,
 
           if (p != null)
             {
-              new_full_name = (p as NameDetails).full_name.strip ();
+              new_full_name = ((NameDetails) p).full_name.strip ();
             }
 
           if (new_full_name != this._full_name)
@@ -1519,7 +1551,7 @@ public class Folks.Individual : Object,
     {
       this._update_single_valued_property (typeof (NameDetails), (p) =>
         {
-          var nickname = (p as NameDetails).nickname;
+          var nickname = ((NameDetails) p).nickname;
           assert (nickname != null);
 
           return (nickname.strip () != ""); /* empty names are unset */
@@ -1533,7 +1565,7 @@ public class Folks.Individual : Object,
 
           if (p != null)
             {
-              new_nickname = (p as NameDetails).nickname.strip ();
+              new_nickname = ((NameDetails) p).nickname.strip ();
             }
 
           if (new_nickname != this._nickname)
@@ -1597,7 +1629,7 @@ public class Folks.Individual : Object,
            * doesn't contain this persona). In this case, we need to set the
            * persona's individual to null. */
           if (replacement_individual != null &&
-              persona in replacement_individual.personas)
+              persona in ((!) replacement_individual).personas)
             {
               persona.individual = replacement_individual;
             }
@@ -1612,7 +1644,7 @@ public class Folks.Individual : Object,
     {
       this._update_single_valued_property (typeof (GenderDetails), (p) =>
         {
-          return (p as GenderDetails).gender != Gender.UNSPECIFIED;
+          return ((GenderDetails) p).gender != Gender.UNSPECIFIED;
         }, (a, b) =>
         {
           /* It would be sexist to rank one gender over another.
@@ -1625,7 +1657,7 @@ public class Folks.Individual : Object,
 
           if (p != null)
             {
-              new_gender = (p as GenderDetails).gender;
+              new_gender = ((GenderDetails) p).gender;
             }
 
           if (new_gender != this.gender)
@@ -1650,11 +1682,8 @@ public class Folks.Individual : Object,
           var url_details = persona as UrlDetails;
           if (url_details != null)
             {
-              foreach (var url_fd in url_details.urls)
+              foreach (var url_fd in ((!) url_details).urls)
                 {
-                  if (url_fd.value == null)
-                    continue;
-
                   var existing = urls_set.get (url_fd.value);
                   if (existing != null)
                     existing.extend_parameters (url_fd.parameters);
@@ -1687,11 +1716,8 @@ public class Folks.Individual : Object,
           var phone_details = persona as PhoneDetails;
           if (phone_details != null)
             {
-              foreach (var phone_fd in phone_details.phone_numbers)
+              foreach (var phone_fd in ((!) phone_details).phone_numbers)
                 {
-                  if (phone_fd.value == null)
-                    continue;
-
                   var existing = phone_numbers_set.get (phone_fd.value);
                   if (existing != null)
                     existing.extend_parameters (phone_fd.parameters);
@@ -1723,11 +1749,8 @@ public class Folks.Individual : Object,
           var email_details = persona as EmailDetails;
           if (email_details != null)
             {
-              foreach (var email_fd in email_details.email_addresses)
+              foreach (var email_fd in ((!) email_details).email_addresses)
                 {
-                  if (email_fd.value == null)
-                    continue;
-
                   var existing = emails_set.get (email_fd.value);
                   if (existing != null)
                     existing.extend_parameters (email_fd.parameters);
@@ -1754,7 +1777,7 @@ public class Folks.Individual : Object,
           var role_details = persona as RoleDetails;
           if (role_details != null)
             {
-              foreach (var role_fd in role_details.roles)
+              foreach (var role_fd in ((!) role_details).roles)
                 {
                   this._roles.add (role_fd);
                 }
@@ -1773,7 +1796,7 @@ public class Folks.Individual : Object,
           var local_ids_details = persona as LocalIdDetails;
           if (local_ids_details != null)
             {
-              foreach (var id in local_ids_details.local_ids)
+              foreach (var id in ((!) local_ids_details).local_ids)
                 {
                   this._local_ids.add (id);
                 }
@@ -1793,7 +1816,7 @@ public class Folks.Individual : Object,
           var address_details = persona as PostalAddressDetails;
           if (address_details != null)
             {
-              foreach (var pafd in address_details.postal_addresses)
+              foreach (var pafd in ((!) address_details).postal_addresses)
                 this._postal_addresses.add (pafd);
             }
         }
@@ -1805,14 +1828,14 @@ public class Folks.Individual : Object,
     {
       this._update_single_valued_property (typeof (BirthdayDetails), (p) =>
         {
-          var details = (p as BirthdayDetails);
+          var details = ((BirthdayDetails) p);
           return details.birthday != null && details.calendar_event_id != null;
         }, (a, b) =>
         {
-          var a_birthday = (a as BirthdayDetails).birthday;
-          var b_birthday = (b as BirthdayDetails).birthday;
-          var a_event_id = (a as BirthdayDetails).calendar_event_id;
-          var b_event_id = (b as BirthdayDetails).calendar_event_id;
+          var a_birthday = ((BirthdayDetails) a).birthday;
+          var b_birthday = ((BirthdayDetails) b).birthday;
+          var a_event_id = ((BirthdayDetails) a).calendar_event_id;
+          var b_event_id = ((BirthdayDetails) b).calendar_event_id;
 
           var a_birthday_is_set = (a_birthday != null) ? 1 : 0;
           var b_birthday_is_set = (b_birthday != null) ? 1 : 0;
@@ -1833,13 +1856,13 @@ public class Folks.Individual : Object,
 
           if (p != null)
             {
-              bday = (p as BirthdayDetails).birthday;
-              calendar_event_id = (p as BirthdayDetails).calendar_event_id;
+              bday = ((BirthdayDetails) p).birthday;
+              calendar_event_id = ((BirthdayDetails) p).calendar_event_id;
             }
 
           if ((this._birthday == null && bday != null) ||
               (this._birthday != null &&
-               (bday == null || !this._birthday.equal (bday))) ||
+               (bday == null || !((!) this._birthday).equal ((!) bday))) ||
               (this._calendar_event_id != calendar_event_id))
             {
               this._birthday = bday;
@@ -1862,7 +1885,7 @@ public class Folks.Individual : Object,
           var note_details = persona as NoteDetails;
           if (note_details != null)
             {
-              foreach (var n in note_details.notes)
+              foreach (var n in ((!) note_details).notes)
                 {
                   this._notes.add (n);
                 }
@@ -1884,7 +1907,7 @@ public class Folks.Individual : Object,
        * assume it's an empty set. */
       if (personas != null)
         {
-          foreach (var p in personas)
+          foreach (var p in (!) personas)
             {
               if (!this._persona_set.contains (p))
                 {
@@ -1922,7 +1945,7 @@ public class Folks.Individual : Object,
         {
           var p = iter.get ();
 
-          if (personas == null || !personas.contains (p))
+          if (personas == null || !((!) personas).contains (p))
             {
               /* Keep track of how many Personas are users */
               if (p.is_user)
@@ -1992,27 +2015,36 @@ public class Folks.Individual : Object,
 
           foreach (var persona in this._persona_set)
             {
-              if (chosen_persona == null ||
-                  (chosen_persona.store.is_primary_store == false &&
+              if (chosen_persona == null)
+                {
+                  chosen_persona = persona;
+                  continue;
+                }
+
+              var _chosen_persona = (!) chosen_persona;
+
+              if ((_chosen_persona.store.is_primary_store == false &&
                       persona.store.is_primary_store == true) ||
-                  (chosen_persona.store.is_primary_store ==
+                  (_chosen_persona.store.is_primary_store ==
                           persona.store.is_primary_store &&
-                      chosen_persona.store.trust_level >
+                      _chosen_persona.store.trust_level >
                           persona.store.trust_level) ||
-                  (chosen_persona.store.is_primary_store ==
+                  (_chosen_persona.store.is_primary_store ==
                           persona.store.is_primary_store &&
-                      chosen_persona.store.trust_level ==
+                      _chosen_persona.store.trust_level ==
                           persona.store.trust_level &&
-                      chosen_persona.store.id > persona.store.id)
+                      _chosen_persona.store.id > persona.store.id)
                  )
                {
                  chosen_persona = persona;
                }
             }
 
-          // Hash the chosen persona's UID
+          /* Hash the chosen persona's UID. We can guarantee chosen_persona is
+           * non-null here because it's at least set to the first element of
+           * this._persona_set, which we've checked is non-empty. */
           this.id = Checksum.compute_for_string (ChecksumType.SHA1,
-              chosen_persona.uid);
+              ((!) chosen_persona).uid);
         }
 
       /* Update our aggregated fields and notify the changes */
diff --git a/folks/note-details.vala b/folks/note-details.vala
index cb0333f..392e1c9 100644
--- a/folks/note-details.vala
+++ b/folks/note-details.vala
@@ -87,7 +87,7 @@ public class Folks.NoteFieldDetails : AbstractFieldDetails<string>
    */
   public override bool equal (AbstractFieldDetails<string> that)
     {
-      return base.equal<string> (that);
+      return base.equal (that);
     }
 
   /**
@@ -97,15 +97,7 @@ public class Folks.NoteFieldDetails : AbstractFieldDetails<string>
    */
   public override uint hash ()
     {
-      uint retval = 0;
-
-      if (this.value != null)
-        retval += this.value.hash ();
-
-      if (this.id != null)
-        retval += this.id.hash ();
-
-      return retval;
+      return (this.value.hash () + this.id.hash ());
     }
 }
 
diff --git a/folks/object-cache.vala b/folks/object-cache.vala
index 5374948..c9adb85 100644
--- a/folks/object-cache.vala
+++ b/folks/object-cache.vala
@@ -52,6 +52,7 @@ public abstract class Folks.ObjectCache<T> : Object
 
   private File _cache_directory;
   private File _cache_file;
+  private string _cache_file_path; /* save calls to _cache_file.get_path() */
 
   /**
    * Get the { link GLib.VariantType} of the serialised form of an object stored
@@ -162,6 +163,8 @@ public abstract class Folks.ObjectCache<T> : Object
       this._cache_file =
           this._cache_directory.get_child (Uri.escape_string (this.id,
               "", false));
+      var path = this._cache_file.get_path ();
+      this._cache_file_path = (path != null) ? (!) path : "(null)";
     }
 
   /**
@@ -184,7 +187,7 @@ public abstract class Folks.ObjectCache<T> : Object
   public async Set<T>? load_objects (Cancellable? cancellable = null)
     {
       debug ("Loading cache (type ID '%s', ID '%s') from file '%s'.",
-          this.type_id, this._id, this._cache_file.get_path ());
+          this.type_id, this._id, this._cache_file_path);
 
       // Read in the file
       uint8[] data;
@@ -202,12 +205,12 @@ public abstract class Folks.ObjectCache<T> : Object
           else if (e is IOError.NOT_FOUND)
             {
               debug ("Couldn't load cache file '%s': %s",
-                  this._cache_file.get_path (), e.message);
+                  this._cache_file_path, e.message);
             }
           else
             {
               warning ("Couldn't load cache file '%s': %s",
-                  this._cache_file.get_path (), e.message);
+                  this._cache_file_path, e.message);
             }
 
           return null;
@@ -217,7 +220,7 @@ public abstract class Folks.ObjectCache<T> : Object
       if (data.length < this._HEADER_WIDTH)
         {
           warning ("Cache file '%s' was too small. The file was deleted.",
-              this._cache_file.get_path ());
+              this._cache_file_path);
           yield this.clear_cache ();
 
           return null;
@@ -231,7 +234,7 @@ public abstract class Folks.ObjectCache<T> : Object
         {
           warning ("Cache file '%s' was version %u of the file format, " +
               "but only version %u is supported. The file was deleted.",
-              this._cache_file.get_path (), wrapper_version,
+              this._cache_file_path, wrapper_version,
               this._FILE_FORMAT_VERSION);
           yield this.clear_cache ();
 
@@ -241,19 +244,20 @@ public abstract class Folks.ObjectCache<T> : Object
       unowned uint8[] variant_data = data[this._HEADER_WIDTH:data.length];
 
       // Deserialise the variant according to the given version numbers
-      var variant_type =
+      var _variant_type =
           this._get_cache_file_variant_type (wrapper_version, object_version);
 
-      if (variant_type == null)
+      if (_variant_type == null)
         {
           warning ("Cache file '%s' was version %u of the object file " +
               "format, which is not supported. The file was deleted.",
-              this._cache_file.get_path (), object_version,
+              this._cache_file_path, object_version,
               this._FILE_FORMAT_VERSION);
           yield this.clear_cache ();
 
           return null;
         }
+      var variant_type = (!) _variant_type;
 
       var variant =
           Variant.new_from_data<uint8[]> (variant_type, variant_data, false,
@@ -263,7 +267,7 @@ public abstract class Folks.ObjectCache<T> : Object
       if (variant.is_normal_form () == false)
         {
           warning ("Cache file '%s' was corrupt and was deleted.",
-              this._cache_file.get_path ());
+              this._cache_file_path);
           yield this.clear_cache ();
 
           return null;
@@ -275,7 +279,7 @@ public abstract class Folks.ObjectCache<T> : Object
       if (type_id != this.type_id)
         {
           warning ("Cache file '%s' had type ID '%s', but '%s' was expected." +
-              "The file was deleted.", this._cache_file.get_path (), type_id,
+              "The file was deleted.", this._cache_file_path, type_id,
               this.type_id);
           yield this.clear_cache ();
 
@@ -287,7 +291,7 @@ public abstract class Folks.ObjectCache<T> : Object
       if (id != this._id)
         {
           warning ("Cache file '%s' had ID '%s', but '%s' was expected." +
-              "The file was deleted.", this._cache_file.get_path (), id,
+              "The file was deleted.", this._cache_file_path, id,
               this._id);
           yield this.clear_cache ();
 
@@ -328,7 +332,7 @@ public abstract class Folks.ObjectCache<T> : Object
       Cancellable? cancellable = null)
     {
       debug ("Storing cache (type ID '%s', ID '%s') to file '%s'.",
-          this.type_id, this._id, this._cache_file.get_path ());
+          this.type_id, this._id, this._cache_file_path);
 
       var child_type = this.get_serialised_object_type (uint8.MAX);
       assert (child_type != null); // uint8.MAX should always be supported
@@ -351,8 +355,10 @@ public abstract class Folks.ObjectCache<T> : Object
         new Variant.array (child_type, children) // Array of objects
       });
 
-      assert (variant.get_type ().equal (
-          this._get_cache_file_variant_type (wrapper_version, object_version)));
+      var desired_variant_type =
+          this._get_cache_file_variant_type (wrapper_version, object_version);
+      assert (desired_variant_type != null &&
+          variant.get_type ().equal ((!) desired_variant_type));
 
       // Prepend the version numbers to the data
       uint8[] data = new uint8[this._HEADER_WIDTH + variant.get_size ()];
@@ -396,7 +402,7 @@ public abstract class Folks.ObjectCache<T> : Object
               /* Print a warning and delete the cache file so we don't leave
                * stale cached objects lying around. */
               warning ("Couldn't write to cache file '%s', so deleting it: %s",
-                  this._cache_file.get_path (), e.message);
+                  this._cache_file_path, e.message);
               yield this.clear_cache ();
 
               return;
@@ -412,7 +418,7 @@ public abstract class Folks.ObjectCache<T> : Object
   public async void clear_cache ()
     {
       debug ("Clearing cache (type ID '%s', ID '%s'); deleting file '%s'.",
-          this.type_id, this._id, this._cache_file.get_path ());
+          this.type_id, this._id, this._cache_file_path);
 
       try
         {
@@ -427,13 +433,14 @@ public abstract class Folks.ObjectCache<T> : Object
   private VariantType? _get_cache_file_variant_type (uint8 wrapper_version,
       uint8 object_version)
     {
-      var object_type = this.get_serialised_object_type (object_version);
+      var _object_type = this.get_serialised_object_type (object_version);
 
-      if (object_type == null)
+      if (_object_type == null)
         {
           // Unsupported version
           return null;
         }
+      var object_type = (!) _object_type;
 
       return new VariantType.tuple ({
         VariantType.STRING, // Type ID
diff --git a/folks/persona-store.vala b/folks/persona-store.vala
index cf43325..fe7d2b2 100644
--- a/folks/persona-store.vala
+++ b/folks/persona-store.vala
@@ -366,8 +366,8 @@ public abstract class Folks.PersonaStore : Object
       var _added = added;
       var _removed = removed;
 
-      if ((added == null || added.size == 0) &&
-          (removed == null || removed.size == 0))
+      if ((added == null || ((!) added).size == 0) &&
+          (removed == null || ((!) removed).size == 0))
         {
           /* Don't bother signalling if nothing's changed */
           return;
@@ -381,8 +381,9 @@ public abstract class Folks.PersonaStore : Object
           _removed = new HashSet<Persona> ();
         }
 
-      this.personas_changed (_added.read_only_view, _removed.read_only_view,
-          message, actor, reason);
+      // We've now guaranteed that both _added and _removed are non-null.
+      this.personas_changed (((!) _added).read_only_view,
+          ((!) _removed).read_only_view, message, actor, reason);
     }
 
   /**
diff --git a/folks/persona.vala b/folks/persona.vala
index f0b3d22..75970fd 100644
--- a/folks/persona.vala
+++ b/folks/persona.vala
@@ -61,7 +61,7 @@ public errordomain Folks.PropertyError
  */
 public abstract class Folks.Persona : Object
 {
-  private weak Individual _individual;
+  private weak Individual? _individual;
 
   /**
    * The internal ID used to represent the Persona for linking.
@@ -151,14 +151,14 @@ public abstract class Folks.Persona : Object
       get
         {
           assert (this._individual == null ||
-              this._individual.personas.contains (this));
+              ((!) this._individual).personas.contains (this));
 
           return this._individual;
         }
 
       internal set
         {
-          assert (value == null || value.personas.contains (this));
+          assert (value == null || ((!) value).personas.contains (this));
 
           this._individual = value;
         }
diff --git a/folks/phone-details.vala b/folks/phone-details.vala
index bc525ff..5e3c652 100644
--- a/folks/phone-details.vala
+++ b/folks/phone-details.vala
@@ -83,7 +83,7 @@ public class Folks.PhoneFieldDetails : AbstractFieldDetails<string>
    */
   public override bool equal (AbstractFieldDetails<string> that)
     {
-      return base.equal<string> (that);
+      return base.equal (that);
     }
 
   /**
@@ -91,9 +91,10 @@ public class Folks.PhoneFieldDetails : AbstractFieldDetails<string>
    */
   public override bool values_equal (AbstractFieldDetails<string> that)
     {
-      var that_fd = that as PhoneFieldDetails;
-      if (that_fd == null)
+      var _that_fd = that as PhoneFieldDetails;
+      if (_that_fd == null)
         return false;
+      PhoneFieldDetails that_fd = (!) _that_fd;
 
       var n1 = this._drop_extension (this.get_normalised ());
       var n2 = this._drop_extension (that_fd.get_normalised ());
diff --git a/folks/postal-address-details.vala b/folks/postal-address-details.vala
index b575a76..5c50b31 100644
--- a/folks/postal-address-details.vala
+++ b/folks/postal-address-details.vala
@@ -307,7 +307,7 @@ public class Folks.PostalAddressFieldDetails :
    */
   public override bool equal (AbstractFieldDetails<PostalAddress> that)
     {
-      if (!base.parameters_equal<PostalAddress> (that))
+      if (!base.parameters_equal (that))
         return false;
 
       /* This is fairly-dumb but smart matching is an i10n nightmare. */
diff --git a/folks/potential-match.vala b/folks/potential-match.vala
index eb4906c..0f2c6dd 100644
--- a/folks/potential-match.vala
+++ b/folks/potential-match.vala
@@ -166,8 +166,6 @@ public class Folks.PotentialMatch : Object
    */
   private void _name_similarity ()
     {
-      Folks.StructuredName a = this._individual_a.structured_name;
-      Folks.StructuredName b = this._individual_b.structured_name;
       double similarity = 0.0;
 
       if (this._look_alike (this._individual_a.nickname,
@@ -182,8 +180,14 @@ public class Folks.PotentialMatch : Object
           similarity += 0.70;
         }
 
-      if (a != null && b != null)
+      var _a = this._individual_a.structured_name;
+      var _b = this._individual_b.structured_name;
+
+      if (_a != null && _b != null)
         {
+          var a = (!) _a;
+          var b = (!) _b;
+
           if (a.is_empty () == false && a.equal (b))
             {
               this._result = MatchResult.HIGH;
@@ -395,8 +399,8 @@ public class Folks.PotentialMatch : Object
           return false;
         }
 
-      bool alike = this.jaro_dist (a, b) >= this._DIST_THRESHOLD ? true : false;
-      return alike;
+      // a and b look alike if their Jaro distance is over the threshold.
+      return (this.jaro_dist ((!) a, (!) b) >= this._DIST_THRESHOLD);
     }
 
   /* Based on:
diff --git a/folks/role-details.vala b/folks/role-details.vala
index b720148..663dad4 100644
--- a/folks/role-details.vala
+++ b/folks/role-details.vala
@@ -220,11 +220,12 @@ public class Folks.RoleFieldDetails : AbstractFieldDetails<Role>
    */
   public override bool equal (AbstractFieldDetails<Role> that)
     {
-      var that_fd = that as RoleFieldDetails;
-      if (that_fd == null)
+      var _that_fd = that as RoleFieldDetails;
+      if (_that_fd == null)
         return false;
+      RoleFieldDetails that_fd = (!) _that_fd;
 
-      if (!base.parameters_equal<Role> (that))
+      if (!base.parameters_equal (that))
         return false;
 
       return Role.equal (this.value, that_fd.value);
diff --git a/folks/url-details.vala b/folks/url-details.vala
index 8b44eb3..e743ddc 100644
--- a/folks/url-details.vala
+++ b/folks/url-details.vala
@@ -102,7 +102,7 @@ public class Folks.UrlFieldDetails : AbstractFieldDetails<string>
    */
   public override bool equal (AbstractFieldDetails<string> that)
     {
-      return base.equal<string> (that);
+      return base.equal (that);
     }
 
   /**
diff --git a/folks/web-service-details.vala b/folks/web-service-details.vala
index c37bbb8..ec2c46d 100644
--- a/folks/web-service-details.vala
+++ b/folks/web-service-details.vala
@@ -64,7 +64,7 @@ public class Folks.WebServiceFieldDetails : AbstractFieldDetails<string>
    */
   public override bool equal (AbstractFieldDetails<string> that)
     {
-      return base.equal<string> (that);
+      return base.equal (that);
     }
 
   /**



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]