Skip to content

Close remaining public-API gaps with upstream Java#260

Merged
rowanseymour merged 1 commit into
mainfrom
chore/java-api-parity-followups
Jun 3, 2026
Merged

Close remaining public-API gaps with upstream Java#260
rowanseymour merged 1 commit into
mainfrom
chore/java-api-parity-followups

Conversation

@rowanseymour

Copy link
Copy Markdown
Member

Follow-ups from comparing this port's public API against libphonenumber's Java reference (v9.0.31), beyond the overload-suffix renames already done in prior PRs.

Changes

1. geocoding: port the missing userRegion overloads

Java's PhoneNumberOfflineGeocoder exposes four public methods; we only had two. Added:

  • GetDescriptionForValidNumberForUserRegion(number, lang, userRegion)
  • GetDescriptionForNumberForUserRegion(number, lang, userRegion)

These omit the country from the description when the number is from the same region as the caller (e.g. "California" for a US caller vs "United States" for a GB caller), otherwise returning the localized country name. Ported the upstream testGetDescriptionForNumberWithUserRegion case, adapted to the production geocoding data.

New public API — note the …ForUserRegion suffix naming for the Java overloads.

2. phonenumbermatcher: unexport six helpers

checkNumberGroupingIsValid, allNumberGroupsRemainGrouped, allNumberGroupsAreExactlyPresent, containsMoreThanOneSlashInNationalNumber, containsOnlyValidXChars, isNationalPrefixPresentIfRequired are package-private in Java and only used internally by Leniency.Verify. They were exported here but never part of Java's public surface.

Breaking for any external caller that imported these — they are no longer exported.

3. enums: reorder ValidationResult to match Java ordinals

New order: IS_POSSIBLE, IS_POSSIBLE_LOCAL_ONLY, INVALID_COUNTRY_CODE, TOO_SHORT, INVALID_LENGTH, TOO_LONG. Comparisons are identity-based throughout, so behaviour is unchanged; this only aligns the constants' integer values with the Java enum.

Notes

None of these introduce new divergences from upstream, so SYNC.md and the reconciled-against version (v9.0.31) are unchanged.

Testing

go build ./..., go vet ./..., gofmt, and go test ./... all pass.

Three follow-ups from comparing the public API against libphonenumber's
Java reference (v9.0.31), beyond the overload-suffix renames already done:

- geocoding: port the two missing userRegion overloads as
  GetDescriptionForValidNumberForUserRegion and
  GetDescriptionForNumberForUserRegion. These omit the country from the
  description when the number is from the same region as the caller, matching
  PhoneNumberOfflineGeocoder. Ports the upstream
  testGetDescriptionForNumberWithUserRegion case (adapted to production data).

- phonenumbermatcher: unexport six helpers that are package-private in Java
  (checkNumberGroupingIsValid, allNumberGroupsRemainGrouped,
  allNumberGroupsAreExactlyPresent, containsMoreThanOneSlashInNationalNumber,
  containsOnlyValidXChars, isNationalPrefixPresentIfRequired). They are only
  used internally by Leniency.Verify and were never part of the Java public
  API.

- enums: reorder the ValidationResult constants to match Java's enum ordinals.
  Comparisons are identity-based, so behaviour is unchanged; this only aligns
  the constants' integer values.

None of these introduce new divergences from upstream, so SYNC.md and the
reconciled-against version are unchanged.
@rowanseymour rowanseymour merged commit 63755f4 into main Jun 3, 2026
6 checks passed
@rowanseymour rowanseymour deleted the chore/java-api-parity-followups branch June 3, 2026 23:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant