Merge "Fix NPE in ComponentNameValidator" into pi-dev

am: b105913098

Change-Id: I9725217151634a66d7cd3dc0e80acb5f78f15c39
This commit is contained in:
Annie Meng
2018-05-17 11:34:33 -07:00
committed by android-build-merger
2 changed files with 7 additions and 2 deletions

View File

@@ -79,7 +79,7 @@ public class SettingsValidators {
public static final Validator COMPONENT_NAME_VALIDATOR = new Validator() {
@Override
public boolean validate(String value) {
return ComponentName.unflattenFromString(value) != null;
return value != null && ComponentName.unflattenFromString(value) != null;
}
};

View File

@@ -16,9 +16,9 @@
package android.provider;
import static org.junit.Assert.fail;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import android.platform.test.annotations.Presubmit;
import android.provider.SettingsValidators.Validator;
@@ -62,6 +62,11 @@ public class SettingsValidatorsTest {
assertFalse(SettingsValidators.COMPONENT_NAME_VALIDATOR.validate("rectangle"));
}
@Test
public void testComponentNameValidator_onNullValue_doesNotThrow() {
assertFalse(SettingsValidators.COMPONENT_NAME_VALIDATOR.validate(null));
}
@Test
public void testLocaleValidator() {
assertTrue(SettingsValidators.LOCALE_VALIDATOR.validate("en_US"));