Really fast way to get a StackOverflowException

From some StoryTeller work this morning after using a ReSharper “Lift Superclass” refactoring:

        public Test Test

        {

            get { return Test; }

            set { Test = value; }

        }

If NUnit ever goes really, really wacky on you and starts to fail, StackOverflowException is a likely candidate. I found this one quick fortunately.

About Jeremy Miller

Jeremy is the Chief Software Architect at Dovetail Software, the coolest ISV in Austin. Jeremy began his IT career writing "Shadow IT" applications to automate his engineering documentation, then wandered into software development because it looked like more fun. Jeremy is the author of the open source StructureMap tool for Dependency Injection with .Net, StoryTeller for supercharged acceptance testing in .Net, and one of the principal developers behind FubuMVC. Jeremy's thoughts on all things software can be found at The Shade Tree Developer at http://codebetter.com/jeremymiller.
This entry was posted in Uncategorized. Bookmark the permalink. Follow any comments here with the RSS feed for this post.
  • Kit

    in Find in Files, do a regex search using this pattern for most ‘get’ cases (I haven’t spent enough time for set, protected get, etc. but this works across lines):

    :i[ \t\n]*{:i}[ \t\n]*\{[ \t\n]*get[ \t\n]*\{[ \t\n]*return[ \t\n]*\1[ \t\n]*;

  • http://www.vikramlakhotia.com Vikram

    Yes agreed, I have suffered with this once. after a silly mistake like that found that the server was hanging as soon as that page was called and hence these can be kept in the compilercheck to to detected as compile time error

  • http://www.ayende.com/Blog Ayende Rahien

    This really should be a compiler _error_.
    There is no condition where this code is valid.

  • http://codebetter.com/blogs/jeremy.miller jmiller

    Nice Chad. I’ve managed to do it twice this week already.

  • http://davidhayden.com/blog/dave/ dhayden

    I second Jim’s comment.

    I have caught this error a couple of times because ReSharper displays a loop icon. A nice feature I didn’t know was there until I needed it.

  • Jim Bolla

    Resharper has a nice feature that adds a little loop icon on the left side of the code window for recursive methods/properties. Makes finding these little nasties fairly easy. Static code analysis during compilation should be able to determine that there are no code paths through a method that DON’T cause recursion and therefore should be a compiler error/warning.

  • http://www.hdri.net Chad Myers

    This is such a prolific problem, I really wish MS would just add a compiler warning for this.

    How ’bout:

    C0019: Hey dummy, did you really mean to cause a StackOverflowException?

  • http://codebetter.com/blogs/jeremy.miller jmiller

    99% of the time I do too, except private Test _test. But when you get sloppy with “Replace All”….

  • http://www.codebetter.com/blogs/eric.wise ewise

    This is one of several reasons why I still use private Test _Test even though it technically isn’t necessary. =)