title: what's the reason for stackoverflow exception in this?
body: <pre><code>import java.math.BigInteger;
  import java.util.HashMap;
  
  /**
   *
   * @author cypronmaya
   */
  public class test {
      static HashMap&lt;Integer, BigInteger&gt; cache = new HashMap&lt;Integer, BigInteger&gt;();
      public static void main(String[] args) {
       System.out.println(factorial(20000));
    }
  
      public static BigInteger factorial(int n) {
          BigInteger ret;
          if (n == 0) {
              return BigInteger.ONE;
          }
          if (null != (ret = cache.get(n))) {
              return ret;
          }
          ret = BigInteger.valueOf(n).multiply(factorial(n - 1));
          cache.put(n, ret);
          return ret;
      }
  }
  </code></pre>
  
  <blockquote>
    <p>Exception in thread "main" java.lang.StackOverflowError   at
    java.util.HashMap.get(Unknown Source)</p>
  </blockquote>
  
  <p>Hi,
  Why am i getting stackoverflow exception to this program?</p>
  
  <p>i know that  stackoverflow usually means you have an infinite loop,
  but this works fine when i'm using 10000 or some other numbers lesser, wht becomes suddenly infinite with big numbers?</p>