Skip to main content

Bug and StackOverflowError

No replies
antuanl
Offline
Joined: 2004-06-20
Points: 0

Hello I think some kind of bug must creep around.
This java.lang.StackOverflowError does not occur on java version 1.5.0_7 while with:

java -version
java version "1.6.0-rc"
Java(TM) SE Runtime Environment (build 1.6.0-rc-b94)
Java HotSpot(TM) Client VM (build 1.6.0-rc-b94, mixed mode, sharing)

Running a linux box (Linux ubunhp 2.6.15-26-386 )
This code :
------------------------------------
public class ackermann {
public static void main(String[] args) {
int num = Integer.parseInt(args[0]);
System.out.println("Ack(3," + num + "): " + Ack(3, num));
}
public static int Ack(int m, int n) {
return (m == 0) ? (n + 1) : ((n == 0) ? Ack(m-1, 1) :
Ack(m-1, Ack(m, n - 1)));
}
}

---------------
Throws

java -Xms30m -Xmx800m -server ackermann 12
Exception in thread "main" java.lang.StackOverflowError
at ackermann.Ack(ackermann.java:10)
at ackermann.Ack(ackermann.java:10)
at ackermann.Ack(ackermann.java:10)
at ackermann.Ack(ackermann.java:10)
at ackermann.Ack(ackermann.java:10)
at ackermann.Ack(ackermann.java:10)
........................................