Fix possible NPE

Fix possible NPE when renaming the tmp dir.
This PR does not need to be rebased.