Why Role::getPermissions() method return an empty array for admin users? Searching the answer for How to get user permissions for the role Administrator? I found that if you try to get the permissions for the admin user you will get an empty array.

From Role::getPermissions():

  /**
   * Returns a list of permissions assigned to the role.
   *
   * @return array
   *   The permissions assigned to the role.
   */
  public function getPermissions() {
    if ($this-&gt;isAdmin()) {
      return [];
    }
    return $this-&gt;permissions;
  }


But if the admin user have all the permissions why Drupal just return an empty array?
That is because a role that is marked with is_admin (which from the UI is possible for just a single role) has all the permissions. Consider it as an extension of the user #1 concept; the difference is that there is just a user #1, but there could be many users assigned to the role marked as is_admin.
In fact, the code does the same it does for the user #1: It explicitly checks for the role being is_admin. So, returning an array of permissions that will never be used doesn't make sense. See Role::hasPermission().

  if ($this-&gt;isAdmin()) {
    return TRUE;
  }
  return in_array($permission, $this-&gt;permissions);


Similar code is present in other functions/methods, for example Role::revokePermission().

  if ($this-&gt;isAdmin()) {
    return $this;
  }
  $this-&gt;permissions = array_diff($this-&gt;permissions, array($permission));
  return $this;


As for why Drupal uses that code, it is because from the UI it is possible to change which role is marked as is_admin, including one for which permissions were already set. Once it is marked is_admin, the permissions explicitly set can be ignored, but they are kept, just in case you change from the UI the role marked as is_admin. In such case, you would not want to set again the permissions you set for the old is_admin role.