Java Exception Stacktrace Not Printing

If you repeatedly throw an exception, the JVM stop filling in the stack trace. I am not sure why but it may be to reduce load on the JVM. You need to be looking at an earlier stack trace to see the details.

for (int n = 0; ; n++) {
    try {
        Integer i = null;
        i.hashCode();
    } catch (Exception e) {
        if (e.getStackTrace().length == 0) {
            System.out.println("No more stack trace after " + n + " thrown.");
            break;
        }
    }

prints

No more stack trace after 20707 thrown.

Does anyone have any ideas about how I can capture the full stack trace to a string?

You can use the below way(StringWriter.toString()) to transfer the stack trace into a String.

 StringWriter writer = new StringWriter();
 e.printStackTrace( new PrintWriter(writer,true ));
 System. out.println("exeption stack is :\n"+writer.toString());

this is beacause java does some code optimiziation when run in server mode (java -server) to skip this. use -XX:-OmitStackTraceInFastThrow in java args see link below for details:

http://jawspeak.com/2010/05/26/hotspot-caused-exceptions-to-lose-their-stack-traces-in-production-and-the-fix/