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 – 2015-04-18T20:46:37.94014I tend to produce by navigating to stackoverflow.com, though I have been known to query 'stack overflow' on my search engine of choice. – OJFord – 2014-02-17T13:19:21.613
It's too bad http://mailinator.blogspot.no/2009/06/beautiful-race-condition.html is just an infinite loop.
– Taemyr – 2014-02-17T14:35:08.2771
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 – 2014-02-17T15:51:59.4031@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 – 2014-02-18T04:14:51.967
@Quincunx Sure; sorry. – Jason C – 2014-02-18T04:41:23.470
21Use Internet Explorer. A sure way to catch one :) – asgoth – 2014-02-18T17:48:19.697
@asgoth explain plz – masterX244 – 2014-02-18T17:53:18.710
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 – 2014-02-18T18:38:08.907didnt 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 – 2014-02-18T18:39:30.767
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 – 2014-02-18T20:19:35.277
post cause some compilers could accept it; (like the TeX example which relies on certain versions – masterX244 – 2014-02-18T20:20:33.530
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 – 2014-02-18T20:32:59.457
3
I'm partial to this method: http://www.joelonsoftware.com/items/2008/09/15.html
– robert – 2014-02-19T13:10:21.493@TimSeguine - that sure sound like recursion to me! – TheDoctor – 2014-02-20T02:11:58.240
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 – 2014-02-19T15:44:14.103I'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 – 2014-02-21T21:20:04.883
11Drive a Toyota (Hey, wait a minute, my car is a Toyota...) – r3mainer – 2014-02-22T01:08:03.487
I used to have a program bug that called a super-method of an overridden method by accident, causing a stack-overflow by the
EventDispatcher
thread, but I can't remember where nor reproduce it. – Mark Jeronimus – 2014-02-26T09:34:58.747