internal: seal singleton-style types with no accessible constructor - #424
Merged
Conversation
PhoneNumberUtil, PhoneNumberOfflineGeocoder, PhoneNumberToCarrierMapper, PhoneNumberToTimeZonesMapper, and ShortNumberInfo all have internal or private constructors and are reached only through GetInstance() - no external assembly could ever have subclassed them, and nothing in this repo does either. MetadataFilter is also sealed: its own doc comment already says it's "an internal API ... not part of the public API", every member but the class declaration and the object overrides is already internal. Verified locally with `dotnet pack -p:VersionPrefix=9.0.38` against the 9.0.37 ApiCompat baseline that sealing these produces zero CP-rule errors - the CP0009 "sealed added" rule only fires for a type with an accessible (public/protected) constructor. (Tried making MetadataFilter `internal` too, matching its doc comment, but that trips CP0001 "type removed" regardless of constructor accessibility, so it stays public and just gains `sealed` - see the correction posted on #375.) Follow-up from the #375 audit. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #424 +/- ##
==========================================
- Coverage 87.46% 87.40% -0.06%
==========================================
Files 41 41
Lines 3837 3835 -2
Branches 984 985 +1
==========================================
- Hits 3356 3352 -4
- Misses 280 281 +1
- Partials 201 202 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
📊 Benchmark Results
PR branch
PR base
|
This was referenced Aug 28, 2026
Closed
Open
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Part of the sealing/visibility audit from #375 (comment: #375 (comment)) — this PR is the "safe now, not blocked on a major version" bucket.
PhoneNumberUtil,PhoneNumberOfflineGeocoder,PhoneNumberToCarrierMapper,PhoneNumberToTimeZonesMapper,ShortNumberInfo→sealed. All are reached only through a staticGetInstance(); their constructors areinternal/private, so no external assembly could ever have derived from them, and nothing in this repo does either.MetadataFilter→sealed. Its own doc comment already says it's "an internal API ... not part of the public API"; every member except the class declaration and theobjectoverrides is alreadyinternal.Verified locally that this is genuinely non-breaking: ran
dotnet pack -p:VersionPrefix=9.0.38against the9.0.37EnablePackageValidationbaseline.sealedon a type with no accessible constructor produces zero ApiCompat errors — theCP0009"sealed added" rule only fires when the baseline type had a public/protected constructor. (I also tried makingMetadataFilterinternaloutright, matching its doc comment, but that tripsCP0001"type removed from the public API surface" regardless of constructor accessibility — so it stayspublic, just sealed. Posted that correction on #375 too.)No behavior change.
Test plan
dotnet build csharp/PhoneNumbers.slnx— clean, 0 warningsdotnet test csharp/PhoneNumbers.slnx -p:TargetFrameworks=net10.0— 450/450 passing (414 PhoneNumbers.Test + 36 PhoneNumbers.Extensions.Test)dotnet pack -c Release csharp/PhoneNumbers -p:VersionPrefix=9.0.38— ApiCompat clean against the 9.0.37 baseline