diff --git a/src/as/com/threerings/util/ArrayUtil.as b/src/as/com/threerings/util/ArrayUtil.as index 8dfa5f029..af840f122 100644 --- a/src/as/com/threerings/util/ArrayUtil.as +++ b/src/as/com/threerings/util/ArrayUtil.as @@ -32,12 +32,20 @@ public class ArrayUtil { /** * Sort the specified array according to natural order- all elements - * must implement Comparable. + * must implement Comparable or be null. */ public static function sort (arr :Array) :void { arr.sort(function (obj1 :Object, obj2 :Object) :int { - return Comparable(obj1).compareTo(obj2); + if (obj1 == obj2) { // same object or both null + return 0; + } else if (obj1 == null) { + return -1; + } else if (obj2 == null) { + return 1; + } else { + return Comparable(obj1).compareTo(obj2); + } }); } diff --git a/src/as/com/threerings/util/SortedHashMap.as b/src/as/com/threerings/util/SortedHashMap.as index 0edf7bd34..4e41f5eeb 100644 --- a/src/as/com/threerings/util/SortedHashMap.as +++ b/src/as/com/threerings/util/SortedHashMap.as @@ -88,6 +88,9 @@ public class SortedHashMap extends HashMap protected function validateKey (key :Object) :void // throws ArgumentError { + if (key == null) { + return; + } switch (_keyType) { case COMPARABLE_KEYS: if (key is Comparable) {