diff --git a/java/libphonenumber/src/com/google/i18n/phonenumbers/ParsingOptions.java b/java/libphonenumber/src/com/google/i18n/phonenumbers/ParsingOptions.java index 5e83a46258..1fc1ceb7ec 100644 --- a/java/libphonenumber/src/com/google/i18n/phonenumbers/ParsingOptions.java +++ b/java/libphonenumber/src/com/google/i18n/phonenumbers/ParsingOptions.java @@ -30,10 +30,7 @@ public class ParsingOptions { public boolean hasDefaultRegion() { return hasDefaultRegion; } public String getDefaultRegion() { return defaultRegion_; } public ParsingOptions setDefaultRegion(String value) { - if (value == null) { - throw new NullPointerException(); - } - hasDefaultRegion = true; + hasDefaultRegion = (value != null); defaultRegion_ = value; return this; } diff --git a/java/libphonenumber/src/com/google/i18n/phonenumbers/PhoneNumberUtil.java b/java/libphonenumber/src/com/google/i18n/phonenumbers/PhoneNumberUtil.java index 6de3061a0f..c09370c8d5 100644 --- a/java/libphonenumber/src/com/google/i18n/phonenumbers/PhoneNumberUtil.java +++ b/java/libphonenumber/src/com/google/i18n/phonenumbers/PhoneNumberUtil.java @@ -3142,6 +3142,10 @@ private boolean checkRegionForParsing(CharSequence numberToParse, String default public PhoneNumber parse(CharSequence numberToParse, String defaultRegion) throws NumberParseException { PhoneNumber phoneNumber = new PhoneNumber(); + parseWithOptions( + numberToParse, + new ParsingOptions().setDefaultRegion(defaultRegion), + phoneNumber); parseWithOptions( numberToParse, new ParsingOptions().setDefaultRegion(defaultRegion), @@ -3161,6 +3165,10 @@ public void parse(CharSequence numberToParse, String defaultRegion, PhoneNumber numberToParse, new ParsingOptions().setDefaultRegion(defaultRegion), phoneNumber); + parseWithOptions( + numberToParse, + new ParsingOptions().setDefaultRegion(defaultRegion), + phoneNumber); } /** @@ -3182,6 +3190,10 @@ public void parse(CharSequence numberToParse, String defaultRegion, PhoneNumber public PhoneNumber parseAndKeepRawInput(CharSequence numberToParse, String defaultRegion) throws NumberParseException { PhoneNumber phoneNumber = new PhoneNumber(); + parseWithOptions( + numberToParse, + new ParsingOptions().setKeepRawInput(true).setDefaultRegion(defaultRegion), + phoneNumber); parseWithOptions( numberToParse, new ParsingOptions().setKeepRawInput(true).setDefaultRegion(defaultRegion), @@ -3249,18 +3261,6 @@ public void parseWithOptions(CharSequence numberToParse, ParsingOptions options, parseHelper(numberToParse, options.getDefaultRegion(), options.isKeepRawInput(), true, phoneNumber); } - public PhoneNumber parseWithOptions(CharSequence numberToParse, ParsingOptions options) - throws NumberParseException { - PhoneNumber phoneNumber = new PhoneNumber(); - parseHelper(numberToParse, options.getDefaultRegion(), options.hasKeepRawInput(), options.hasDefaultRegion(), phoneNumber); - return phoneNumber; - } - - public void parseWithOptions(CharSequence numberToParse, ParsingOptions options, PhoneNumber phoneNumber) - throws NumberParseException { - parseHelper(numberToParse, options.getDefaultRegion(), options.hasKeepRawInput(), options.hasDefaultRegion(), phoneNumber); - } - /** * Returns an iterable over all {@link PhoneNumberMatch PhoneNumberMatches} in {@code text}. This * is a shortcut for {@link #findNumbers(CharSequence, String, Leniency, long)