146
49
As a programmer you certainly know the error of a stack overflow due to an obvious recursion. But there are certainly many weird and unusual ways to get your favourite language to spit that error out.
Objectives:
- Must cause a stack overflow which is clearly visible on the error output.
- Not allowed to use an obvious recursion.
Examples of invalid programs:
// Invalid, direct obvious recursion.
methodA(){ methodA(); }
// Invalid, indirect, but obvious recursion.
methodA(){ methodB(); }
methodB(){ methodA(); }
The most creative ways are the best as this a popularity-contest. I.e, avoid boring obvious answers like this:
throw new StackOverflowError(); // Valid, but very boring and downvote-deserving.
Even though I accepted an answer now, adding more answers is still okay :)



Here is the weirdest way to produce a StackOverflow. Get a time machine. Go back to 2008. Create a vote-based, community-run question-and-answer site about programming questions, where users can post their problems and get reliable results. Come back to your current time. Edit this post with the URL of your Q&A site. This should generate a StackOverflow. EDIT: I did it, here is my site: http://stackoverflow.com/
– ASCIIThenANSI – 11 years ago14I tend to produce by navigating to stackoverflow.com, though I have been known to query 'stack overflow' on my search engine of choice. – OJFord – 12 years ago
It's too bad http://mailinator.blogspot.no/2009/06/beautiful-race-condition.html is just an infinite loop.
– Taemyr – 12 years ago1
There are many good (and short!) answers here: http://codegolf.stackexchange.com/questions/9359/shortest-program-that-throws-stackoverflow-error. I hope nobody will copy those answers.
– VisioN – 12 years ago1@JasonC You don't need to advertise your posts on this question with a comment. The OP owner will get a notification, and anyone who would upvote or such will find the answer without needing to read your comment. – Justin – 12 years ago
@Quincunx Sure; sorry. – Jason C – 12 years ago
21Use Internet Explorer. A sure way to catch one :) – asgoth – 12 years ago
@asgoth explain plz – masterX244 – 12 years ago
1@masterX244 I mean, IE can produce javascript errors (e.g.
stackoverflow at line 0), while the code runs fine in other browsers. My comment was meant to be sarcastic. Sorry if it failed. – asgoth – 12 years agodidnt knew that one thats why i asked @asgoth avoiding Internet Exploder since multiple years so the bugs didnt fgound a way into my memory – masterX244 – 12 years ago
Hey does it have to compile? I have given an example of one that would overflow, but compilers will refuse to compile it because the behavior is never intended, not because it is semantically wrong. (C++ - constructor to construct temporary to pass to constructor causes infinite loop at runtime) – Alec Teal – 12 years ago
post cause some compilers could accept it; (like the TeX example which relies on certain versions – masterX244 – 12 years ago
64The weirdest way to produce a stack overflow is to post a popularity-contest on codegolf.stackexchange.com asking for people to post the weirdest way to produce a stack overflow. The responders, in testing their solutions to the question, will produce a stack overflow. I haven't tested it though, so I can't be sure it works (which is why I didn't post it as an answer). – Tim Seguine – 12 years ago
3
I'm partial to this method: http://www.joelonsoftware.com/items/2008/09/15.html
– robert – 12 years ago@TimSeguine - that sure sound like recursion to me! – TheDoctor – 12 years ago
2
#Quine# This is only an idea (one specific implementation in Java can be found here). A quine is a program that produces it's own code. If you take it a step further, you can make the code be saved to file and compiled during run time, then executed. This will not cause a classic StackOverFlow error, but a (much more risky...) disk memory overflow.
– Elist – 12 years agoI'm presuming that the goal is to cause an actual stack overflow, rather than to simply throw a StackOverflowError or whatever your language calls it. – keshlam – 12 years ago
11Drive a Toyota (Hey, wait a minute, my car is a Toyota...) – r3mainer – 12 years ago
I used to have a program bug that called a super-method of an overridden method by accident, causing a stack-overflow by the
EventDispatcherthread, but I can't remember where nor reproduce it. – Mark Jeronimus – 12 years ago