Backport of gh-30286

Comment From: sbrannen

Closed in 91c58af7af27d22d116ac5ad64380277022f210a

Comment From: asjp1970

Hi, This new method doesn't work for empty collections. We were using 5.3.24 before, where nullSafeToString was used instead, and in case, for instance of an empty ArrayList, it returned the string "[]" as representation of the empty collection (because it ended up calling the proper toString method in java.util.AbstractCollection).

Now this method decides that cannot handle emtpy collections and returns:

return type.getTypeName() + "@" + getIdentityHexString(obj);

thus ignoring the possible toString implementation of anything not matching the if's in lines 947 and 954.

I will issue a ticket.

Probably we are missing unit tests here... I know that they can be in the grey area of testing the obvious, but in this case the fault with empty collections would not have slept through.