Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

java.lang.StackOverflowError

 
Ranch Hand
Posts: 459
6
Netbeans IDE Oracle Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ranchers,

I found a question who I give me trouble from

http://www.ejavaguru.com/freeresources/examquestiontypes-exp.html



Of course. the exception java.lang.StackOverflowError is excepted, but I don't understand the below message:

at sun.nio.cs.UTF_8.updatePositions(UTF_8.java:77)
at sun.nio.cs.UTF_8$Encoder.encodeArrayLoop(UTF_8.java:564)
at sun.nio.cs.UTF_8$Encoder.encodeLoop(UTF_8.java:619)
at java.nio.charset.CharsetEncoder.encode(CharsetEncoder.java:561)
at sun.nio.cs.StreamEncoder.implWrite(StreamEncoder.java:271)
at sun.nio.cs.StreamEncoder.write(StreamEncoder.java:125)
at java.io.OutputStreamWriter.write(OutputStreamWriter.java:207)
at java.io.BufferedWriter.flushBuffer(BufferedWriter.java:129)
at java.io.PrintStream.write(PrintStream.java:526)
at java.io.PrintStream.print(PrintStream.java:669)
at java.io.PrintStream.println(PrintStream.java:806)
at main6.Main6.main(Main6.java:19)
at main6.Main6.main(Main6.java:24)
at main6.Main6.main(Main6.java:25)
at main6.Main6.main(Main6.java:25)
at main6.Main6.main(Main6.java:25)
at main6.Main6.main(Main6.java:25)
at main6.Main6.main(Main6.java:25)

Thanks a lot.

 
Ranch Hand
Posts: 261
15
Android Angular Framework Spring AngularJS Java
  • Likes 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, Dana:
That's a rather interesting question.  First, (sorry if you already knew) that's called a "stack trace".  When the overflow took place, an exception was thrown, and then the JVM handled it by printing this stack trace and exiting.

What makes it interesting, however, is the order in which things are printed.  Here's an explanation of how these work.  http://docs.oracle.com/javase/7/docs/api/java/lang/Throwable.html#printStackTrace()

The link I gave is claiming that the "low level exception" should appear at the bottom as the "caused by" exception.  However, I think there is no chain of catch/throw going on here: just one exception that is the only cause.



The recursive calls made through "main(String[] args)" calling  "main()" were filling up the stack.  But the stack did not hit its limit until deep down in the implementation of the println() call.  I will hazard a guess here, that if your maximum stack size were different (controlled using "-Xss4m" at the command line), you might see this crash in a different place.  That "println()" seems to go surprisingly deep, and maybe that will cause the overflow to happen there more often (even with different stack sizes).  Once the code returns from that println, the stack 'depth' will get shallower by that many levels.  The next recursion call will push it down one level deep, and then a second level to go into "main()", and then Boom! you dive into "println()" again.

I hope that helps.
 
L Foster
Ranch Hand
Posts: 261
15
Android Angular Framework Spring AngularJS Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
BTW, Dana:

Here's another method that will let you have some fun with this concept, if you can stand seeing all the output.

https://docs.oracle.com/javase/7/docs/api/java/lang/Thread.html#dumpStack()

This static method on "Thread" can help you see just how deep the stack is getting.  You can also simply do this:



You can get a stack trace out of an exception without actually throwing an exception.
 
Dana Ucaed
Ranch Hand
Posts: 459
6
Netbeans IDE Oracle Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I will try, thanks for your replay.

 
    Bookmark Topic Watch Topic
  • New Topic