Magento 2 Invoice addComment() error

In Magento 2.4.8, calling Invoice::getComments() before Invoice::addComment() can cause a fatal Call to a member function addItem() on array error due to inconsistent handling of the comments data key.