diff --git a/java/libphonenumber/src/com/google/i18n/phonenumbers/PhoneNumberUtil.java b/java/libphonenumber/src/com/google/i18n/phonenumbers/PhoneNumberUtil.java index 1ac393321..76212c6b2 100644 --- a/java/libphonenumber/src/com/google/i18n/phonenumbers/PhoneNumberUtil.java +++ b/java/libphonenumber/src/com/google/i18n/phonenumbers/PhoneNumberUtil.java @@ -1449,9 +1449,11 @@ public class PhoneNumberUtil { break; } // Otherwise, we need to remove the national prefix from our output. - formatRule.clearNationalPrefixFormattingRule(); + NumberFormat numFormatCopy = new NumberFormat(); + numFormatCopy.mergeFrom(formatRule); + numFormatCopy.clearNationalPrefixFormattingRule(); List numberFormats = new ArrayList(1); - numberFormats.add(formatRule); + numberFormats.add(numFormatCopy); formattedNumber = formatByPattern(number, PhoneNumberFormat.NATIONAL, numberFormats); break; } diff --git a/java/libphonenumber/test/com/google/i18n/phonenumbers/PhoneNumberUtilTest.java b/java/libphonenumber/test/com/google/i18n/phonenumbers/PhoneNumberUtilTest.java index ea480c017..be62ef847 100644 --- a/java/libphonenumber/test/com/google/i18n/phonenumbers/PhoneNumberUtilTest.java +++ b/java/libphonenumber/test/com/google/i18n/phonenumbers/PhoneNumberUtilTest.java @@ -823,6 +823,8 @@ public class PhoneNumberUtilTest extends TestCase { phoneUtil.parseAndKeepRawInput("2087654321", RegionCode.GB); assertEquals("20 8765 4321", phoneUtil.formatInOriginalFormat(numberWithoutNationalPrefixGB, RegionCode.GB)); + // Make sure no metadata is modified as a result of the previous function call. + assertEquals("(020) 8765 4321", phoneUtil.formatInOriginalFormat(number5, RegionCode.GB)); PhoneNumber numberWithNationalPrefixMX = phoneUtil.parseAndKeepRawInput("013312345678", RegionCode.MX);