Fix class-cast exception which is a regression introduces in 256c931db20fbfaf597e501b74a34fd850c7f948