Fix NPE when passing a null charset, close #651