diff --git a/core/lib/Drupal/Component/Utility/SortArray.php b/core/lib/Drupal/Component/Utility/SortArray.php
index 0ed5bbc..38710b9 100644
--- a/core/lib/Drupal/Component/Utility/SortArray.php
+++ b/core/lib/Drupal/Component/Utility/SortArray.php
@@ -50,7 +50,7 @@ public static function sortByWeightElement(array $a, array $b) {
    * @return int
    *   The comparison result for uasort().
    */
-  public static function sortByWeightProperty($a, $b) {
+  public static function sortByWeightProperty(array $a, array $b) {
     return static::sortByKeyInt($a, $b, '#weight');
   }
 
@@ -68,7 +68,7 @@ public static function sortByWeightProperty($a, $b) {
    * @return int
    *   The comparison result for uasort().
    */
-  public static function sortByTitleElement($a, $b) {
+  public static function sortByTitleElement(array $a, array $b) {
     return static::sortByKeyString($a, $b, 'title');
   }
 
@@ -86,7 +86,7 @@ public static function sortByTitleElement($a, $b) {
    * @return int
    *   The comparison result for uasort().
    */
-   public static function sortByTitleProperty($a, $b) {
+   public static function sortByTitleProperty(array $a, array $b) {
      return static::sortByKeyString($a, $b, '#title');
    }
 
@@ -103,9 +103,9 @@ public static function sortByTitleProperty($a, $b) {
    * @return int
    *   The comparison result for uasort().
    */
-  public static function sortByKeyString($a, $b, $key) {
-    $a_title = (is_array($a) && isset($a[$key])) ? $a[$key] : '';
-    $b_title = (is_array($b) && isset($b[$key])) ? $b[$key] : '';
+  public static function sortByKeyString(array $a, array $b, $key) {
+    $a_title = isset($a[$key]) ? $a[$key] : '';
+    $b_title = isset($b[$key]) ? $b[$key] : '';
 
     return strnatcasecmp($a_title, $b_title);
   }
@@ -123,9 +123,9 @@ public static function sortByKeyString($a, $b, $key) {
    * @return int
    *   The comparison result for uasort().
    */
-  public static function sortByKeyInt($a, $b, $key) {
-    $a_weight = (is_array($a) && isset($a[$key])) ? $a[$key] : 0;
-    $b_weight = (is_array($b) && isset($b[$key])) ? $b[$key] : 0;
+  public static function sortByKeyInt(array $a, array $b, $key) {
+    $a_weight = isset($a[$key]) ? $a[$key] : 0;
+    $b_weight = isset($b[$key]) ? $b[$key] : 0;
 
     if ($a_weight == $b_weight) {
       return 0;
diff --git a/core/modules/system/src/Form/ModulesListForm.php b/core/modules/system/src/Form/ModulesListForm.php
index 73b32ec..fe482f8 100644
--- a/core/modules/system/src/Form/ModulesListForm.php
+++ b/core/modules/system/src/Form/ModulesListForm.php
@@ -199,7 +199,6 @@ public function buildForm(array $form, FormStateInterface $form_state) {
     uasort($modules, 'system_sort_modules_by_info_name');
 
     // Iterate over each of the modules.
-    $form['modules']['#tree'] = TRUE;
     foreach ($modules as $filename => $module) {
       if (empty($module->info['hidden'])) {
         $package = $module->info['package'];
@@ -234,6 +233,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
     // Lastly, sort all packages by title.
     uasort($form['modules'], array('\Drupal\Component\Utility\SortArray', 'sortByTitleProperty'));
 
+    $form['modules']['#tree'] = TRUE;
     $form['#attached']['library'][] = 'system/drupal.system.modules';
     $form['actions'] = array('#type' => 'actions');
     $form['actions']['submit'] = array(
