Skip to content

Commit

Permalink
Be defensive on special case of method node lacking an identifier.
Browse files Browse the repository at this point in the history
  • Loading branch information
Corniel Nobel committed Jul 14, 2022
1 parent 0cebad0 commit 948024d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ protected override void Initialize(SonarAnalysisContext context)
Language.GeneratedCodeRecognizer,
c =>
{
if (IsRegexMatchMethod(Language.Syntax.NodeIdentifier(c.Node).Value.Text)
if (IsRegexMatchMethod(Language.Syntax.NodeIdentifier(c.Node).GetValueOrDefault().Text)
&& RegexMethodLacksTimeout(c.Node, c.SemanticModel))
{
c.ReportIssue(Diagnostic.Create(Rule, c.Node.GetLocation()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ Namespace TestCasesForRuleFailure
Public Sub ParamsMethod(i As Integer, ParamArray j() As Integer)
End Sub

Public Sub ArgListMethod(__arglist)
ArgListMethod("__arglist"(""))
End Sub

Public Shared Widening Operator CType(c As SpecialCases) As String
Return ""
End Operator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ void Static(RegexOptions options)
}
}

class DoesNotCrash
{
void MethodWitoutIdentifier(__arglist)
{
MethodWitoutIdentifier(__arglist(""));
}
}

namespace NoSystem
{
public class Regex
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,9 @@ Class Noncompliant
Dim split = Regex.Split("some input", "some pattern", options) ' Noncompliant
End Sub
End Class

Class DoesNotCrash
Private Sub MethodWitoutIdentifier(__arglist)
MethodWitoutIdentifier("__arglist"(""))
End Sub
End Class

0 comments on commit 948024d

Please sign in to comment.