Preferences: Fix crash issues due to nullPointerException