Skip to content

Commit a3d01cb

Browse files
CopilotChrisPulman
andauthored
Replace catch(NullReferenceException) with IsDefaultOrEmpty guard in AttributeDataExtensions
The NamedArguments property returns a default ImmutableArray when attribute data is incomplete/malformed at analysis time. Guard with .IsDefaultOrEmpty before iterating rather than swallowing NullReferenceException, which could mask real Roslyn API bugs. Agent-Logs-Url: https://github.com/reactiveui/ReactiveUI.SourceGenerators/sessions/7c58663a-a9ce-4cfa-a3ff-9a57bc0347a9 Co-authored-by: ChrisPulman <4910015+ChrisPulman@users.noreply.github.com>
1 parent 446665e commit a3d01cb

1 file changed

Lines changed: 6 additions & 8 deletions

File tree

src/ReactiveUI.SourceGenerators.Roslyn/Core/Extensions/AttributeDataExtensions.cs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ public static bool TryGetNamedArgument<T>(this AttributeData attributeData, stri
3737
return false;
3838
}
3939

40-
try
40+
// NamedArguments returns a default ImmutableArray when attribute data is incomplete/malformed.
41+
// Guard with IsDefaultOrEmpty rather than catching NullReferenceException to avoid masking real bugs.
42+
if (!attributeData.NamedArguments.IsDefaultOrEmpty)
4143
{
4244
foreach (var properties in attributeData.NamedArguments)
4345
{
@@ -47,9 +49,6 @@ public static bool TryGetNamedArgument<T>(this AttributeData attributeData, stri
4749
}
4850
}
4951
}
50-
catch (NullReferenceException)
51-
{
52-
}
5352

5453
value = default;
5554

@@ -70,7 +69,9 @@ public static bool TryGetNamedArgument<T>(this AttributeData attributeData, stri
7069
return default;
7170
}
7271

73-
try
72+
// NamedArguments returns a default ImmutableArray when attribute data is incomplete/malformed.
73+
// Guard with IsDefaultOrEmpty rather than catching NullReferenceException to avoid masking real bugs.
74+
if (!attributeData.NamedArguments.IsDefaultOrEmpty)
7475
{
7576
foreach (var properties in attributeData.NamedArguments)
7677
{
@@ -80,9 +81,6 @@ public static bool TryGetNamedArgument<T>(this AttributeData attributeData, stri
8081
}
8182
}
8283
}
83-
catch (NullReferenceException)
84-
{
85-
}
8684

8785
return default;
8886
}

0 commit comments

Comments
 (0)