Sanity check the length, logging and truncating if too long, to avoid a StringIndexOutOfBoundsException (bug #54925)