Java: remove obsolete code that treated numbers where we had no metadata as valid.
authorLara Scheidegger <lararennie@google.com>
Mon, 22 Sep 2014 10:19:28 +0000 (10:19 +0000)
committerYoungjae Shin <yj99.shin@samsung.com>
Tue, 9 Jun 2015 11:43:20 +0000 (20:43 +0900)
java/libphonenumber/src/com/google/i18n/phonenumbers/PhoneNumberUtil.java
java/libphonenumber/test/com/google/i18n/phonenumbers/PhoneNumberUtilTest.java
java/libphonenumber/test/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProtoForTesting_CC
java/libphonenumber/test/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProtoForTesting_CX
resources/PhoneNumberMetadataForTesting.xml

index b6625ab..1f996f2 100644 (file)
@@ -1981,9 +1981,7 @@ public class PhoneNumberUtil {
   }
 
   private PhoneNumberType getNumberTypeHelper(String nationalNumber, PhoneMetadata metadata) {
-    PhoneNumberDesc generalNumberDesc = metadata.getGeneralDesc();
-    if (!generalNumberDesc.hasNationalNumberPattern() ||
-        !isNumberMatchingDesc(nationalNumber, generalNumberDesc)) {
+    if (!isNumberMatchingDesc(nationalNumber, metadata.getGeneralDesc())) {
       return PhoneNumberType.UNKNOWN;
     }
 
@@ -2114,16 +2112,7 @@ public class PhoneNumberUtil {
       // match that of the region code.
       return false;
     }
-    PhoneNumberDesc generalNumDesc = metadata.getGeneralDesc();
     String nationalSignificantNumber = getNationalSignificantNumber(number);
-
-    // For regions where we don't have metadata for PhoneNumberDesc, we treat any number passed in
-    // as a valid number if its national significant number is between the minimum and maximum
-    // lengths defined by ITU for a national significant number.
-    if (!generalNumDesc.hasNationalNumberPattern()) {
-      int numberLength = nationalSignificantNumber.length();
-      return numberLength > MIN_LENGTH_FOR_NSN && numberLength <= MAX_LENGTH_FOR_NSN;
-    }
     return getNumberTypeHelper(nationalSignificantNumber, metadata) != PhoneNumberType.UNKNOWN;
   }
 
@@ -2382,18 +2371,6 @@ public class PhoneNumberUtil {
     // Metadata cannot be null because the country calling code is valid.
     PhoneMetadata metadata = getMetadataForRegionOrCallingCode(countryCode, regionCode);
     PhoneNumberDesc generalNumDesc = metadata.getGeneralDesc();
-    // Handling case of numbers with no metadata.
-    if (!generalNumDesc.hasNationalNumberPattern()) {
-      logger.log(Level.FINER, "Checking if number is possible with incomplete metadata.");
-      int numberLength = nationalNumber.length();
-      if (numberLength < MIN_LENGTH_FOR_NSN) {
-        return ValidationResult.TOO_SHORT;
-      } else if (numberLength > MAX_LENGTH_FOR_NSN) {
-        return ValidationResult.TOO_LONG;
-      } else {
-        return ValidationResult.IS_POSSIBLE;
-      }
-    }
     Pattern possibleNumberPattern =
         regexCache.getPatternForRegex(generalNumDesc.getPossibleNumberPattern());
     return testNumberLengthAgainstPattern(possibleNumberPattern, nationalNumber);
index 30d26cd..5664268 100644 (file)
@@ -1314,18 +1314,6 @@ public class PhoneNumberUtilTest extends TestMetadataTestCase {
 
     assertEquals(PhoneNumberUtil.ValidationResult.TOO_LONG,
                  phoneUtil.isPossibleNumberWithReason(INTERNATIONAL_TOLL_FREE_TOO_LONG));
-
-    // Try with number that we don't have metadata for.
-    PhoneNumber adNumber = new PhoneNumber();
-    adNumber.setCountryCode(376).setNationalNumber(12345L);
-    assertEquals(PhoneNumberUtil.ValidationResult.IS_POSSIBLE,
-                 phoneUtil.isPossibleNumberWithReason(adNumber));
-    adNumber.setCountryCode(376).setNationalNumber(1L);
-    assertEquals(PhoneNumberUtil.ValidationResult.TOO_SHORT,
-                 phoneUtil.isPossibleNumberWithReason(adNumber));
-    adNumber.setCountryCode(376).setNationalNumber(123456789012345678L);
-    assertEquals(PhoneNumberUtil.ValidationResult.TOO_LONG,
-                 phoneUtil.isPossibleNumberWithReason(adNumber));
   }
 
   public void testIsNotPossibleNumber() {
@@ -2350,7 +2338,7 @@ public class PhoneNumberUtilTest extends TestMetadataTestCase {
     assertEquals("+37612345", phoneUtil.format(adNumber, PhoneNumberFormat.E164));
     assertEquals("12345", phoneUtil.format(adNumber, PhoneNumberFormat.NATIONAL));
     assertEquals(PhoneNumberUtil.PhoneNumberType.UNKNOWN, phoneUtil.getNumberType(adNumber));
-    assertTrue(phoneUtil.isValidNumber(adNumber));
+    assertFalse(phoneUtil.isValidNumber(adNumber));
 
     // Test dialing a US number from within Andorra.
     assertEquals("00 1 650 253 0000",
index f715e55..97fa27e 100644 (file)
Binary files a/java/libphonenumber/test/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProtoForTesting_CC and b/java/libphonenumber/test/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProtoForTesting_CC differ
index b6984d8..ad6bff5 100644 (file)
Binary files a/java/libphonenumber/test/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProtoForTesting_CX and b/java/libphonenumber/test/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProtoForTesting_CX differ
index ae670ca..6e598f7 100644 (file)
     <!-- Cocos Islands -->
     <!-- Country calling code shared with Australia. -->
     <!-- This country is used to test ShortNumberInfo, so at least the country calling code must be
-         recognised by the library. However, we don't want all numbers to be considered valid for
-         it, so we set at least a general description that allows our test geocoding numbers to be
-         valid only for Australia. -->
+         recognised by the library. -->
     <territory id="CC" countryCode="61">
-      <generalDesc>
-        <nationalNumberPattern>5\d{3,14}</nationalNumberPattern>
-        <possibleNumberPattern>\d{2,14}</possibleNumberPattern>
-      </generalDesc>
     </territory>
 
     <!-- China -->
         </numberFormat>
       </availableFormats>
     </territory>
-    
+
     <!-- Christmas Islands -->
     <!-- Country calling code shared with Australia. -->
     <!-- This country is used to test ShortNumberInfo, so at least the country calling code must be
-         recognised by the library. However, we don't want all numbers to be considered valid for
-         it, so we set at least a general description that allows our test geocoding numbers to be
-         valid only for Australia. -->
+         recognised by the library. -->
     <territory id="CX" countryCode="61">
-      <generalDesc>
-        <nationalNumberPattern>5\d{3,14}</nationalNumberPattern>
-        <possibleNumberPattern>\d{2,14}</possibleNumberPattern>
-      </generalDesc>
     </territory>
 
     <!-- Germany -->