1 package gov.nasa.jpf.jvm; 20 21 24 public class TestException { 25 int data; 26 27 void foo () { 28 } 29 30 static void bar () { 31 TestException o = null; 32 o.foo(); 33 } 34 35 public static void main (String [] args) { 36 if (args.length > 0) { 37 for (int i = 0; i < args.length; i++) { 39 String func = args[i]; 40 41 if ("testNPE".equals(func)) { testNPE(); } 44 else if ("testNPECall".equals(func)) { testNPECall(); } 45 else if ("testArrayIndexOutOfBoundsLow".equals(func)) { testArrayIndexOutOfBoundsLow(); } 46 else if ("testArrayIndexOutOfBoundsHigh".equals(func)) { testArrayIndexOutOfBoundsHigh(); } 47 else if ("testLocalHandler".equals(func)) { testLocalHandler(); } 48 else if ("testCallerHandler".equals(func)) { testCallerHandler(); } 49 else { 50 throw new IllegalArgumentException ("unknown test function"); 51 } 52 } 53 } else { 54 testNPE(); 55 testNPECall(); 56 testArrayIndexOutOfBoundsLow(); 57 testArrayIndexOutOfBoundsHigh(); 58 testLocalHandler(); 59 testCallerHandler(); 60 } 61 } 62 63 static void testNPE () { 64 TestException o = null; 65 o.data = -1; 66 67 assert false : "should never get here"; 68 } 69 70 static void testNPECall () { 71 TestException o = null; 72 o.foo(); 73 74 assert false : "should never get here"; 75 } 76 77 static void testArrayIndexOutOfBoundsLow () { 78 int[] a = new int[10]; 79 a[-1] = 0; 80 81 assert false : "should never get here"; 82 } 83 84 static void testArrayIndexOutOfBoundsHigh () { 85 int[] a = new int[10]; 86 a[10] = 0; 87 88 assert false : "should never get here"; 89 } 90 91 static void testLocalHandler () { 92 try { 93 TestException o = null; 94 o.data = 0; 95 } catch (IllegalArgumentException iax) { 96 assert false : "should never get here"; 97 } catch (NullPointerException npe) { 98 return; 99 } catch (Exception x) { 100 assert false : "should never get here"; 101 } 102 103 assert false : "should never get here"; 104 } 105 106 static void testCallerHandler () { 107 try { 108 bar(); 109 } catch (Throwable t) { 110 return; 111 } 112 113 assert false : "should never get here"; 114 } 115 116 } 117 118 | Popular Tags |