Skip to content

Commit 79c08bf

Browse files
docs(net): refresh CA2000 rationale on BowireHttpClientFactory.Create
Pragma stays — HttpClient ctor's ownership transfer is genuinely intractable for the analyzer (try/catch null-out dance just trades CA2000 for CA1508). Refreshed comment to explain why the structural workaround doesn't help here.
1 parent 5b94748 commit 79c08bf

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

src/Kuestenlogik.Bowire/Net/BowireHttpClientFactory.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,14 @@ public static class BowireHttpClientFactory
3939
/// <param name="timeout">Optional client timeout. Default: <c>HttpClient</c> default (100 s).</param>
4040
public static HttpClient Create(IConfiguration? config, string pluginId, TimeSpan? timeout = null)
4141
{
42-
// Ownership of the handler transfers to HttpClient via
43-
// disposeHandler:true — Dispose runs through to the handler when
44-
// the caller disposes the client. CA2000 can't follow that
45-
// ownership transfer across the constructor.
42+
// CA2000: handler ownership transfers to HttpClient via
43+
// disposeHandler:true. HttpClient's ctor never throws for a non-
44+
// null handler, and the only follow-up statement (`client.Timeout =
45+
// ...`) executes after ownership has moved into the client — so
46+
// no leak path exists. A try/catch null-out dance just trades the
47+
// warning for CA1508 ("variable is always null") because the
48+
// analyzer also can't model that ownership transfer. Pragma is
49+
// the honest answer.
4650
#pragma warning disable CA2000
4751
var handler = CreateHandler(config, pluginId);
4852
#pragma warning restore CA2000

0 commit comments

Comments
 (0)