diff --git a/java/libphonenumber/src/com/google/i18n/phonenumbers/PhoneNumberUtil.java b/java/libphonenumber/src/com/google/i18n/phonenumbers/PhoneNumberUtil.java index 8e497dd72..d46fdb161 100644 --- a/java/libphonenumber/src/com/google/i18n/phonenumbers/PhoneNumberUtil.java +++ b/java/libphonenumber/src/com/google/i18n/phonenumbers/PhoneNumberUtil.java @@ -3232,9 +3232,8 @@ public class PhoneNumberUtil { int numberEnd = numberToParse.indexOf(";", numberStart); if (numberEnd < 0) { - // If there is no semicolon, we assume the rest of the string is the national number. - // This should not happen, since we expect to find a semicolon if there is a phone-context. - numberEnd = numberToParse.length(); + throw new NumberParseException(NumberParseException.ErrorType.NOT_A_NUMBER, + "The string supplied did not seem to be a phone number."); } String numberPart = numberToParse.substring(numberStart, numberEnd); diff --git a/java/libphonenumber/test/com/google/i18n/phonenumbers/PhoneNumberUtilTest.java b/java/libphonenumber/test/com/google/i18n/phonenumbers/PhoneNumberUtilTest.java index 1c0e27e31..0b0250023 100644 --- a/java/libphonenumber/test/com/google/i18n/phonenumbers/PhoneNumberUtilTest.java +++ b/java/libphonenumber/test/com/google/i18n/phonenumbers/PhoneNumberUtilTest.java @@ -2954,6 +2954,9 @@ public class PhoneNumberUtilTest extends TestMetadataTestCase { assertThrowsForInvalidPhoneContext("tel:033316005;phone-context=3phone"); assertThrowsForInvalidPhoneContext("tel:033316005;phone-context=a-.nz"); assertThrowsForInvalidPhoneContext("tel:033316005;phone-context=a{b}c"); + + // The phone-context parameter comes before the phone number. + assertThrowsForInvalidPhoneContext(";phone-context=+64;tel:03-331-6005"); } private void assertThrowsForInvalidPhoneContext(String numberToParse) {