Avoid deprecation in checking for valid list. (reverted from commit dfbd194810cc24ccac7b81d1ee7b38e4ca68f0c8)
When testing, encode buffered StringIO using UTF-8, to avoid JRuby-specific encoding issues.