CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

Jeremy D. Miller -- The Shade Tree Developer

Under the hood and working with .Net, TDD, Software Design, and Agile Stuff

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.



Comments

Eric Wise said:

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

# March 20, 2007 9:01 AM

Jeremy D. Miller said:

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

# March 20, 2007 9:03 AM

Chad Myers said:

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?

# March 20, 2007 9:57 AM

Jim Bolla said:

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.

# March 20, 2007 10:05 AM

David Hayden said:

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.

# March 20, 2007 10:16 AM

Jeremy D. Miller said:

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

# March 20, 2007 10:22 AM

Ayende Rahien said:

This really should be a compiler _error_.

There is no condition where this code is valid.

# March 20, 2007 11:20 AM

Vikram said:

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

# March 22, 2007 11:08 PM

Kit said:

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]*;

# October 29, 2007 1:06 PM

Leave a Comment

(required)  
(optional)
(required)  

Enter the numbers above:
Add

About Jeremy D. Miller

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 previously worked as a systems architect building mission critical supply chain software for a Fortune 100 company and learned agile development practices as a .Net consultant at ThoughtWorks, one of the pioneers of agile development. Jeremy is the author of the open source StructureMap (http://structuremap.sourceforge.net) tool for Dependency Injection with .Net and the forthcoming StoryTeller (http://storyteller.tigris.org) tool for supercharged FIT testing in .Net. Jeremy's thoughts on just about everything software related can be found on his weblog "The Shade Tree Developer" at http://codebetter.com/blogs/jeremy.miller, part of the popular CodeBetter site. Jeremy is a Microsoft MVP for C#. Check out Devlicio.us!

This Blog

Syndication

News

All opinions expressed here constitute my (Jeremy D. Miller's) personal opinion, and do not necessarily represent the opinion of any other organization or person, including (but not limited to) my fellow employees, my employer, its clients or their agents.

About Me

"Best Of" Compendium

StructureMap (Dependency Injection for .Net)

StoryTeller (Supercharged Fit)

Build your own Cab

TestDriven

MVP