Exception in thread "AWT-EventQueue-0" java.lang.StackOverflowError

hi, i have a recursive method.. it works fine (it's when using wordWrap=true) when the StringBuffer input contains 2KB file. When parsing larger file (600KB) i got this exception:

Exception in thread "AWT-EventQueue-0" java.lang.StackOverflowError

at xtext.breakLines(xtext.java:308)

at xtext.breakLines(xtext.java:315)

at xtext.breakLines(xtext.java:318)

at xtext.breakLines(xtext.java:315)

at xtext.breakLines(xtext.java:315)

at xtext.breakLines(xtext.java:315)

at xtext.breakLines(xtext.java:315)

at xtext.breakLines(xtext.java:315)

at xtext.breakLines(xtext.java:315)

at xtext.breakLines(xtext.java:315)

at xtext.breakLines(xtext.java:315)

at xtext.breakLines(xtext.java:315)

at xtext.breakLines(xtext.java:315)

at xtext.breakLines(xtext.java:315)

at xtext.breakLines(xtext.java:315)

at xtext.breakLines(xtext.java:315)

at xtext.breakLines(xtext.java:315)

at xtext.breakLines(xtext.java:315)

at xtext.breakLines(xtext.java:315)

at xtext.breakLines(xtext.java:318)

then it just repeats from line 318 to another ...

method source:

305public String breakLines (StringBuffer input,int pos,int lineLength) {

306

307if (wordWrap) {

308if (input.length()>lineLength && pos <= input.length()) {

309if (pos > 1) {

310 boolean currSpace = Character.isSpaceChar(input.charAt(pos));

311if (currSpace) {

312input.setCharAt(pos,eol);

313breakLines (input,pos+lineLength,lineLength);

314} else {

315breakLines (input,pos-1,lineLength);

316}

317} else {

318breakLines (input,pos+lineLength,lineLength);

319}

320} else {

321 log.append(input.toString());

322

323}

324}

325else {

326while (pos<input.length()) {

327input.insert(pos,"-");

328pos += lineLength;

329}

330}

331

332return input.toString();

333}

what should i do? where's my fault. or is there another simplier way to parse the input wrapping words after x chars (lineLength) ? thanx for supp. starenka>

[2206 byte] By [starenka_oggovaa] at [2007-10-2 8:32:42]
# 1

The reason for stackoverflowerror is obvious. This is cannot be strictly called as your mistake. This is a limitation....when using a 600kb file, you'd be calling the methods recursively a few thousand times (I presume,just add a counter to check) and hence the error. Why can't you try to convert the string into a char array and then pass it into a loop to limit it to the size you need. I strongly feel that there is definitely a way out of this. Don't use recursive method calling unless you are sure it is controlled and won't explode.

anthropocentriquea at 2007-7-16 22:33:54 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...