Similar PR with #32767 , but this is for Joomla 4. The fix for warning on category view of com_contact not included because I have a separate PR to clean up code for com_contact
Testing Instructions
You need to have PHP 8 running to test this PR
Install latest Joomla 4.0-dev
Unpublish all menu items you created to link to one of the following menu item types: List All Categories in an Article Category Tree, Category List, Category Blog .
Create an instance of Articles - Categories, publish it
Access to a category which is displayed in the module above
Before patch: You would get the warning like
Attempt to read property "id" on null in components/com_content/src/View/Category/HtmlView.php
Easier way to replicate
Joomla 4 Admin - Go to write a new article, click save, and click PREVIEW, and in the preview lick the Uncategorised link in the breadcrumbs: