From 6514ab640e742070d2a6f4964c5d99808b49f420 Mon Sep 17 00:00:00 2001 From: Thomas Clegg Date: Sat, 5 Sep 2026 00:04:09 -0500 Subject: [PATCH 1/2] fix: stop the obsolete leading-zero setter calling an obsolete method Resolves the cs/call-to-obsolete-method CodeQL alerts. The query excludes a call whose *enclosing callable* is itself marked [Obsolete], but attributes on a property do not reach its accessors, so the back-compat shim below was flagged even though it is deprecated code calling deprecated code. PhoneNumber.Builder.ItalianLeadingZero's setter now writes through SetNumberOfLeadingZeros(value ? 1 : 0) instead of SetItalianLeadingZero(value). SetItalianLeadingZero's entire body is that same write plus `return this` (discarded here), and its own [Obsolete] message names SetNumberOfLeadingZeros as the replacement, so this is the documented migration and the observable behaviour is unchanged. The property, its [Obsolete] marker and the public signature all stay exactly as they were; line 170 was SetItalianLeadingZero's only caller. The three MetadataManager.SetMetadataLoader calls in TestMedataManager are deliberately left alone. That member's [Obsolete] message names no replacement - it is slated to become internal rather than to be superseded - so there is nothing to migrate to, and the two tests exist specifically to cover that entry point. They keep their narrowly scoped CS0618 pragma; the comment above it now records why the CodeQL alerts on those lines should be dismissed rather than "fixed" by rewriting the tests away from the API under test. --- csharp/PhoneNumbers.Test/TestMedataManager.cs | 5 +++++ csharp/PhoneNumbers/Phonenumber.cs | 5 ++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/csharp/PhoneNumbers.Test/TestMedataManager.cs b/csharp/PhoneNumbers.Test/TestMedataManager.cs index 50c6c4a10..18234dc11 100644 --- a/csharp/PhoneNumbers.Test/TestMedataManager.cs +++ b/csharp/PhoneNumbers.Test/TestMedataManager.cs @@ -60,6 +60,11 @@ public void TestAlternateFormatsFailsGracefully() /// // IMetadataLoader/EmbeddedResourceMetadataLoader/SetMetadataLoader are Obsolete for external // callers only; this test exercises them directly as this project's own internal API. + // The Obsolete message names no replacement — the member is slated to become internal, not + // to be superseded — so there is nothing for these calls to migrate to, and covering the + // deprecated entry point is exactly what the two tests below are for. CodeQL's + // cs/call-to-obsolete-method still reports them; dismiss those alerts rather than + // rewriting the tests away from the API under test. #pragma warning disable CS0618 [Fact] public void SetMetadataLoader_RoutesLookupsThroughCustomLoader() diff --git a/csharp/PhoneNumbers/Phonenumber.cs b/csharp/PhoneNumbers/Phonenumber.cs index df6b261be..9aee2de07 100644 --- a/csharp/PhoneNumbers/Phonenumber.cs +++ b/csharp/PhoneNumbers/Phonenumber.cs @@ -167,7 +167,10 @@ public string Extension public bool ItalianLeadingZero { get => MessageBeingBuilt.ItalianLeadingZero; - set => SetItalianLeadingZero(value); + // Goes straight to the replacement rather than through the equally-obsolete + // SetItalianLeadingZero: that method is nothing but + // SetNumberOfLeadingZeros(value ? 1 : 0), so this is the same write. + set => SetNumberOfLeadingZeros(value ? 1 : 0); } public bool HasNumberOfLeadingZeros => MessageBeingBuilt.HasNumberOfLeadingZeros; From 5f28309dc6087847a622b65e1154ef55a9b46212 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 5 Sep 2026 18:47:03 +0000 Subject: [PATCH 2/2] test: exercise the ItalianLeadingZero setter this PR changed The existing coverage near this code (TestNonEqualWithItalianLeadingZeroSetToTrue) calls SetNumberOfLeadingZeros directly, so nothing in the suite actually invokes the obsolete ItalianLeadingZero property setter this PR just changed to stop calling SetItalianLeadingZero. Add a test that goes through the property itself. --- csharp/PhoneNumbers.Test/TestPhonenumber.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/csharp/PhoneNumbers.Test/TestPhonenumber.cs b/csharp/PhoneNumbers.Test/TestPhonenumber.cs index efd29e305..5798345f6 100644 --- a/csharp/PhoneNumbers.Test/TestPhonenumber.cs +++ b/csharp/PhoneNumbers.Test/TestPhonenumber.cs @@ -59,6 +59,23 @@ public void TestNonEqualWithItalianLeadingZeroSetToTrue() Assert.False(numberA.GetHashCode() == numberB.GetHashCode()); } + [Fact] + public void TestItalianLeadingZeroSetterWritesNumberOfLeadingZeros() + { + // Exercises the obsolete ItalianLeadingZero property setter itself, not + // SetNumberOfLeadingZeros directly, since that setter is what delegates to + // SetNumberOfLeadingZeros(value ? 1 : 0) under the hood. +#pragma warning disable CS0618 // intentionally exercising the obsolete setter + var builder = new PhoneNumber.Builder() + .SetCountryCode(1).SetNationalNumber(6502530000L); + builder.ItalianLeadingZero = true; + Assert.Equal(1, builder.NumberOfLeadingZeros); + + builder.ItalianLeadingZero = false; + Assert.Equal(0, builder.NumberOfLeadingZeros); +#pragma warning restore CS0618 + } + [Fact] public void TestNonEqualWithDifferingRawInput() {