This can happen if you are trying to share records with an inactive user or when you are assigning inactive user as the record owner .Make sure that you filter your query to include only active users with isActive=true .Certainly this is an error in apex and not an SFDC bug
Mohith Shrivastava
- 91.9k
- 19
- 161
- 214