diff --git a/src/com/android/settings/notification/ZenModeStarredContactsPreferenceController.java b/src/com/android/settings/notification/ZenModeStarredContactsPreferenceController.java index 28475b6b5e3..10a7b561353 100644 --- a/src/com/android/settings/notification/ZenModeStarredContactsPreferenceController.java +++ b/src/com/android/settings/notification/ZenModeStarredContactsPreferenceController.java @@ -68,7 +68,10 @@ public class ZenModeStarredContactsPreferenceController extends public void displayPreference(PreferenceScreen screen) { super.displayPreference(screen); mPreference = screen.findPreference(KEY); - mPreference.setOnPreferenceClickListener(this); + + if (mPreference != null) { + mPreference.setOnPreferenceClickListener(this); + } } @Override diff --git a/tests/robotests/src/com/android/settings/notification/ZenModeStarredContactsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/ZenModeStarredContactsPreferenceControllerTest.java index 064c0911319..ad8e0de7193 100644 --- a/tests/robotests/src/com/android/settings/notification/ZenModeStarredContactsPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/notification/ZenModeStarredContactsPreferenceControllerTest.java @@ -190,4 +190,13 @@ public class ZenModeStarredContactsPreferenceControllerTest { assertThat(contacts.get(i)).isNotNull(); } } + + @Test + public void nullPreference_displayPreference() { + when(mPreferenceScreen.findPreference(mMessagesController.getPreferenceKey())) + .thenReturn(null); + + // should not throw a null pointer + mMessagesController.displayPreference(mPreferenceScreen); + } }