Merge "Fix NPE when casting" into pi-dev