Home | History | Annotate | Download | only in src
      1 /*
      2  * Copyright (C) 2007 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 /**
     18  * generate a stack overflow condition and catch it
     19  */
     20 public class Main {
     21     public static void main(String args[]) {
     22         testSelfRecursion();
     23         testMutualRecursion();
     24         System.out.println("SOE test done");
     25     }
     26 
     27     private static void testSelfRecursion() {
     28 //        try {
     29 //            stackOverflowTestSub0();
     30 //        }
     31 //        catch (StackOverflowError soe) {
     32 //            System.out.println("caught SOE0 in testSelfRecursion");
     33 //        }
     34         try {
     35             stackOverflowTestSub3(0.0, 1.0, 2.0);
     36         }
     37         catch (StackOverflowError soe) {
     38             System.out.println("caught SOE3 in testSelfRecursion");
     39         }
     40         try {
     41             stackOverflowTestSub10(0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0);
     42         }
     43         catch (StackOverflowError soe) {
     44             System.out.println("caught SOE10 in testSelfRecursion");
     45         }
     46     }
     47 
     48     private static void stackOverflowTestSub0() {
     49         stackOverflowTestSub0();
     50     }
     51 
     52     private static void stackOverflowTestSub3(double pad1, double pad2, double pad3) {
     53         stackOverflowTestSub3(pad1, pad2, pad3);
     54     }
     55 
     56     private static void stackOverflowTestSub10(double pad1, double pad2, double pad3, double pad4,
     57                                                double pad5, double pad6, double pad7, double pad8,
     58                                                double pad9, double pad10) {
     59         stackOverflowTestSub10(pad1, pad2, pad3, pad4, pad5, pad6, pad7, pad8, pad9, pad10);
     60     }
     61 
     62     private static void testMutualRecursion() {
     63         try {
     64             foo(0.0, 0.0, 0.0);
     65         }
     66         catch (StackOverflowError soe) {
     67             System.out.println("caught SOE in testMutualRecursion");
     68         }
     69     }
     70 
     71     private static void foo(double pad1, double pad2, double pad3) {
     72         bar(pad1, pad2, pad3);
     73     }
     74 
     75     private static void bar(double pad1, double pad2, double pad3) {
     76         baz(pad1, pad2, pad3);
     77     }
     78 
     79     private static void baz(double pad1, double pad2, double pad3) {
     80         qux(pad1, pad2, pad3);
     81     }
     82 
     83     private static void qux(double pad1, double pad2, double pad3) {
     84         foo(pad1, pad2, pad3);
     85     }
     86 }
     87