test/java/lang/Thread/UncaughtExceptions.sh

Print this page




  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 #
  27 # @test
  28 # @bug 4833089 4992454
  29 # @summary Check for proper handling of uncaught exceptions
  30 # @author Martin Buchholz
  31 #
  32 # @run shell UncaughtExceptions.sh
  33 
  34 # To run this test manually, simply do ./UncaughtExceptions.sh
  35 
  36  java="${TESTJAVA+${TESTJAVA}/bin/}java"
  37 javac="${TESTJAVA+${TESTJAVA}/bin/}javac"
  38 
  39 failed=""
  40 Fail() { echo "FAIL: $1"; failed="${failed}."; }
  41 
  42 Die() { printf "%s\n" "$*"; exit 1; }
  43 
  44 Sys() {
  45     "$@"; rc="$?";
  46     test "$rc" -eq 0 || Die "Command \"$*\" failed with exitValue $rc";
  47 }
  48 
  49 HorizontalRule() {
  50     echo "-----------------------------------------------------------------"
  51 }
  52 
  53 Bottom() {
  54     test "$#" = 1 -a "$1" = "Line" || Die "Usage: Bottom Line"
  55 
  56     HorizontalRule
  57     if test -n "$failed"; then


 104     }
 105 }
 106 
 107 class NeverInvoked implements UncaughtExceptionHandler {
 108     public void uncaughtException(Thread t, Throwable e) {
 109         err.println("Test failure: This handler should never be invoked!");
 110     }
 111 }
 112 
 113 public class Seppuku extends Thread implements Runnable {
 114     public static void seppuku() { throw new RuntimeException("Seppuku!"); }
 115 
 116     public void run() { seppuku(); }
 117 
 118     public static void main(String[] args) throws Exception {
 119         $mainBody
 120     }
 121 }
 122 EOJAVA
 123 
 124     Sys "$javac" "Seppuku.java"
 125     CheckCommandResults "$expectedRC" "$expectedOut" "$expectedErr" \
 126         "$java" "Seppuku"
 127     Cleanup
 128 }
 129 
 130 #----------------------------------------------------------------
 131 # A thread is never alive after you've join()ed it.
 132 #----------------------------------------------------------------
 133 Run 0 "OK" "Exception in thread \"Thread-0\".*Seppuku" "
 134     Thread t = new Seppuku();
 135     t.start(); t.join();
 136     if (! t.isAlive())
 137         out.println(\"OK\");"
 138 
 139 #----------------------------------------------------------------
 140 # Even the main thread is mortal - here it terminates "abruptly"
 141 #----------------------------------------------------------------
 142 Run 1 "OK" "Exception in thread \"main\".*Seppuku" "
 143     final Thread mainThread = currentThread();
 144     new Thread() { public void run() {




  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 #
  27 # @test
  28 # @bug 4833089 4992454
  29 # @summary Check for proper handling of uncaught exceptions
  30 # @author Martin Buchholz
  31 #
  32 # @run shell UncaughtExceptions.sh
  33 
  34 # To run this test manually, simply do ./UncaughtExceptions.sh
  35 
  36  java="${TESTJAVA+${TESTJAVA}/bin/}java"
  37 javac="${COMPILEJAVA+${COMPILEJAVA}/bin/}javac"
  38 
  39 failed=""
  40 Fail() { echo "FAIL: $1"; failed="${failed}."; }
  41 
  42 Die() { printf "%s\n" "$*"; exit 1; }
  43 
  44 Sys() {
  45     "$@"; rc="$?";
  46     test "$rc" -eq 0 || Die "Command \"$*\" failed with exitValue $rc";
  47 }
  48 
  49 HorizontalRule() {
  50     echo "-----------------------------------------------------------------"
  51 }
  52 
  53 Bottom() {
  54     test "$#" = 1 -a "$1" = "Line" || Die "Usage: Bottom Line"
  55 
  56     HorizontalRule
  57     if test -n "$failed"; then


 104     }
 105 }
 106 
 107 class NeverInvoked implements UncaughtExceptionHandler {
 108     public void uncaughtException(Thread t, Throwable e) {
 109         err.println("Test failure: This handler should never be invoked!");
 110     }
 111 }
 112 
 113 public class Seppuku extends Thread implements Runnable {
 114     public static void seppuku() { throw new RuntimeException("Seppuku!"); }
 115 
 116     public void run() { seppuku(); }
 117 
 118     public static void main(String[] args) throws Exception {
 119         $mainBody
 120     }
 121 }
 122 EOJAVA
 123 
 124     Sys "$javac" ${TESTJAVACOPTS} ${TESTTOOLVMOPTS} "Seppuku.java"
 125     CheckCommandResults "$expectedRC" "$expectedOut" "$expectedErr" \
 126         "$java" "Seppuku"
 127     Cleanup
 128 }
 129 
 130 #----------------------------------------------------------------
 131 # A thread is never alive after you've join()ed it.
 132 #----------------------------------------------------------------
 133 Run 0 "OK" "Exception in thread \"Thread-0\".*Seppuku" "
 134     Thread t = new Seppuku();
 135     t.start(); t.join();
 136     if (! t.isAlive())
 137         out.println(\"OK\");"
 138 
 139 #----------------------------------------------------------------
 140 # Even the main thread is mortal - here it terminates "abruptly"
 141 #----------------------------------------------------------------
 142 Run 1 "OK" "Exception in thread \"main\".*Seppuku" "
 143     final Thread mainThread = currentThread();
 144     new Thread() { public void run() {