Issue with getting Region Code String for short numbers such as +61000 +61112 in Australia

117 views
Skip to first unread message

Mayuukh Varshney

unread,
Nov 30, 2023, 5:52:22 AM11/30/23
to libphonenumber-discuss

Hi,

I'm writing to report a possible bug encountered while working with the com.google.i18n.phonenumbers.PhoneNumber class in Java, specifically version 8.13.26(Also with 8.12.57). The issue arises when attempting to retrieve the region code for Emergency short numbers originating in Australia.

The relevant code snippet is as follows:

PhoneNumber phoneNumber =com.google.i18n.phonenumbers.PhoneNumberUtil.getInstance().parse("+61000""ZZ"); StringcountryRegionCode = phoneNumber.getRegionCodeForNumber(phoneNumber);

The expected outcome is for countryRegionCode to be populated with "AU," but it currently returns null. After investigation, it appears that the problem lies within the getMetaDataForRegion function in the MetaDataSourceImpl class. Specifically, the getPossibleLengthList which is a List<Integer>, contains phone numbers lengths starting from 5. This doesn't accurately reflect the lengths of emergency helpline numbers in Australia (e.g., +61000, +61112) which can be of size 3(disregarding the national number prefix i.e 61)

As a consequence, the getNumberTypeHelper function in the PhoneNumberUtil class categorizes the number as Unknown, leading to a null value in the getRegionCodeForNumber call.

I would appreciate clarification on whether this behavior is intentional or if it might be considered a bug that requires attention. Your guidance on this matter would be highly appreciated.

Thank you

Lara

unread,
Dec 18, 2023, 5:21:32 AM12/18/23
to libphonenumber-discuss
This is intentional, although without more context on what you are trying to do it is hard to advise exactly how to do it.

A couple of points:
- Checking validity and type for short numbers in general should be handled by ShortNumberInfo instead, so this is not considered a bug
- If you want to know the region, given you already have +61 (which, since short numbers are not usually valid outside the country, I assume was automatically added as a prefix, or alternative you can get via getCountryCode() on the parsed number), you probably want to call getRegionCodesForCountryCode (or getRegionCodeForCountryCode to return the "main" one like AU)

Hope this helps,

Lara
Reply all
Reply to author
Forward
0 new messages