1 #!/bin/sh 2 3 # 4 # Copyright (c) 2002, 2014 Oracle and/or its affiliates. All rights reserved. 5 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 6 # 7 # This code is free software; you can redistribute it and/or modify it 8 # under the terms of the GNU General Public License version 2 only, as 9 # published by the Free Software Foundation. 10 # 11 # This code is distributed in the hope that it will be useful, but WITHOUT 12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 # version 2 for more details (a copy is included in the LICENSE file that 15 # accompanied this code). 16 # 17 # You should have received a copy of the GNU General Public License version 18 # 2 along with this work; if not, write to the Free Software Foundation, 19 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 # 21 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 # or visit www.oracle.com if you need additional information or have any 23 # questions. 24 # 25 26 # @test 27 # @bug 4671838 28 # @summary TTY: surprising ExceptionSpec.resolveEventRequest() wildcard results 29 # @author Tim Bell 30 # 31 # @key intermittent 32 # @run shell CatchPatternTest.sh 33 classname=CatchPatternTestTarg 34 createJavaFile() 35 { 36 cat <<EOF > $classname.java.1 37 public class $classname { 38 public void bark(int i) { 39 System.out.println(" bark: " + i); 40 switch (i) { 41 case 0: 42 throw new IllegalArgumentException("IllegalArgumentException"); 43 case 1: 44 throw new ArithmeticException("ArithmeticException"); 45 case 2: 46 throw new IllegalMonitorStateException("IllegalMonitorStateException"); 47 case 3: 48 throw new IndexOutOfBoundsException("IndexOutOfBoundsException"); 49 default: 50 throw new Error("should not happen"); 51 } 52 } 53 public void loop(int max) { 54 for (int i = 0; i <= max; i++) { 55 try { 56 bark(i); 57 } catch(RuntimeException re) { 58 System.out.println(" loop: " + re.getMessage() + 59 " caught and ignored."); 60 } 61 } 62 } 63 public void partOne() { 64 loop(2); 65 System.out.println("partOne completed"); 66 } 67 public void partTwo() { 68 loop(3); 69 System.out.println("partTwo completed"); 70 } 71 public static void main(String[] args) { 72 System.out.println("Howdy!"); 73 $classname my = new $classname(); 74 my.partOne(); 75 my.partTwo(); 76 System.out.println("Goodbye from $classname!"); 77 } 78 } 79 EOF 80 } 81 82 # This is called to feed cmds to jdb. 83 dojdbCmds() 84 { 85 #set -x 86 cmd stop in ${classname}.main 87 cmd stop in ${classname}.partTwo 88 runToBkpt 89 cmd ignore uncaught java.lang.Throwable 90 # Instead of matching java.lang.I* we use two more specific 91 # patterns here. The reason is to avoid matching IncompatibleClassChangeError 92 # (or the subclass NoSuchMethodError) thrown by the 93 # java.lang.invoke infrastructure. 94 cmd catch all java.lang.Il* 95 cmd catch all java.lang.Ind* 96 cmd cont 97 cmd cont 98 cmd cont 99 cmd ignore all java.lang.I* 100 cmd allowExit cont 101 } 102 103 mysetup() 104 { 105 if [ -z "$TESTSRC" ] ; then 106 TESTSRC=. 107 fi 108 109 for ii in . $TESTSRC $TESTSRC/.. ; do 110 if [ -r "$ii/ShellScaffold.sh" ] ; then 111 . $ii/ShellScaffold.sh 112 break 113 fi 114 done 115 } 116 117 # You could replace this next line with the contents 118 # of ShellScaffold.sh and this script will run just the same. 119 mysetup 120 121 runit 122 # 123 jdbFailIfNotPresent "Exception occurred: java.lang.IllegalArgumentException" 124 jdbFailIfNotPresent "Exception occurred: java.lang.IllegalMonitorStateException" 125 jdbFailIfPresent "Exception occurred: ArithmeticException" 126 jdbFailIfPresent "Exception occurred: IndexOutOfBoundsException" 127 jdbFailIfPresent "Exception occurred: IllegalStateException" 128 jdbFailIfPresent "should not happen" 129 debuggeeFailIfNotPresent "partOne completed" 130 debuggeeFailIfNotPresent "partTwo completed" 131 # 132 pass