I'd propose List<String> hosts = null before try block and return hosts at the end to minimize returns