Finding and fixing StackOverFlowError in java

I was having a problem with some java one day, I’d made a change to some code and I kept getting a StackOverflowError. Unfortunately the stack trace didn’t help and some time inspecting the code didn’t offer any quick solutions. So I turned obviously to Google. The answer was simple, although it took some work to find it.

If you get a StackOverflowError in java it can sometimes be difficult to identify where the problem is occurring. This is because in some versions of the JVM the relevant stack trace isn’t automatically provided. This is the case in 1.4.2 when using the JIT compiler. (which I was)

One work around that worked for me was to add the -Xint option to the java call. This forces the JVM to use interpret the code rather than attempt to compile it. The interpreter will provide a stack trace and the problem can be easily found and fixed.

The bug report that gave the answer is at Sun:
Bug Report.

This entry was posted in General, Macintosh. Bookmark the permalink.

2 Responses to Finding and fixing StackOverFlowError in java

  1. Saurabh Bobde says:

    Great. This piece of information was really useful in identifying the problem, which otherwise could’ve taken us an unknown amount of time. Some of the top results from Google too didn’t help point this out so simplistically!

    Thanks for the information – its been a grrreat help!

  2. Angus Hardie says:

    Glad I could be of help. 🙂

Leave a Reply