Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix S4220 : Rule should not throw StackOverflowException #1129

Merged
merged 1 commit into from
Feb 1, 2018
Merged

Conversation

kvpt
Copy link
Contributor

@kvpt kvpt commented Feb 1, 2018

Hi,

We encountered a StackOverflow in one of our projects during the build when using the sonar c# analyser.

After a divide and conquer strategy, I was able to isolate the code and deduce the faulty rule.

It's a very specific combination of criteria :

  • An encapsuled EventHandler without event keyword
  • A nested conditionnal access and invoke of the handler
    In this case the method GetEventSymbol get called in infinite loop.

Here, the reproduction case and the fix.

There may be better way to handle this case, I don't know well the roselyn api.

Copy link
Contributor

@michalb-sonar michalb-sonar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, needs a small tweak.

[TestCategory("Rule")]
public void EventHandlerDelegateShouldHaveProperArgumentsShoudNotStackOverflow()
{
Verifier.VerifyNoExceptionThrown(@"TestCases\EventHandlerDelegateShouldHaveProperArguments.StackOverflow.Fixed.cs", new []
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use .Fixed.cs convention for code fixes.

Please remove this test method and move the test to EventHandlerDelegateShouldHaveProperArguments.cs. Preferably to a separate class/namespace with a comment on what it is testing.

@kvpt
Copy link
Contributor Author

kvpt commented Feb 1, 2018

I made the modifications.
I merged the test case and removed the test since the existing test is also affected by the problem.

@michalb-sonar michalb-sonar merged commit db3c19d into SonarSource:master Feb 1, 2018
@michalb-sonar
Copy link
Contributor

Thank you for a quick change @kvpt. We appreciate your contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants