Fix false throw of IllegalArgumentException and false encoding