Fix incorrect throw of IllegalStateException