Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/ExceptionEvent/catchLocation/location001a.java
41161 views
/*1* Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223package nsk.jdi.ExceptionEvent.catchLocation;2425import nsk.share.*;26import nsk.share.jpda.*;27import nsk.share.jdi.*;2829import java.lang.Integer.*;30import java.io.*;3132// THIS TEST IS LINE NUMBER SENSITIVE3334// This class is the debugged application in the test3536class location001a {37static final int PASSED = 0;38static final int FAILED = 2;39static final int JCK_STATUS_BASE = 95;4041// synchronization commands42static final String COMMAND_READY = "ready";43static final String COMMAND_QUIT = "quit";44static final String COMMAND_GO = "go";45static final String COMMAND_DONE = "done";46static final String COMMAND_ERROR = "error";4748// line numbers where checked exceptions thrown (for user exceptions only)49public static final int userExceptionLocation = 98;50public static final int userErrorLocation = 105;51public static final int userThrowableLocation = 112;5253// line numbers where checked exceptions caught. Numbers were changed due to 474012354public static final int userExceptionCatchLocation = 99;55public static final int userErrorCatchLocation = 106;56public static final int userThrowableCatchLocation = 113;57public static final int javaExceptionCatchLocation = 120;58public static final int javaErrorCatchLocation = 127;5960// flags marked all actually thrown exceptions61private static boolean userExceptionThrown = false;62private static boolean userErrorThrown = false;63private static boolean userThrowableThrown = false;64private static boolean javaExceptionThrown = false;65private static boolean javaErrorThrown = false;6667// run debuggee from command line68public static void main(String args[]) throws Throwable {69location001a _location001a = new location001a();70System.exit(JCK_STATUS_BASE + _location001a.runIt(args, System.err));71}7273// perform debuggee class execution74int runIt(String args[], PrintStream out) throws Throwable {75ArgumentHandler argHandler = new ArgumentHandler(args);76IOPipe pipe = argHandler.createDebugeeIOPipe();77Log log = new Log(out, argHandler);7879// create checked exceptions80location001aException e1 = new location001aException ();81location001aError e2 = new location001aError ();82location001aThrowable e3 = new location001aThrowable ();8384// notify debugger that debuggee started85pipe.println(COMMAND_READY);8687// wait for command <GO> from debugger88String command = pipe.readln();89if (!command.equals(COMMAND_GO)) {90log.complain("TEST BUG: unknown command: " + command);91return FAILED;92}9394// throw checked exceptions95try {96try {97throw new location001aException(); // userExceptionLocation98} catch (location001aException e) { // <= expected catch location due to evaluation of 4740123. // userExceptionLocation99log.display("location001aException is thrown");100userExceptionThrown = true;101}102103try {104throw new location001aError(); // userErrorLocation105} catch (location001aError e) { // <= expected catch location due to evaluation of 4740123. // userErrorCatchLocation106log.display("location001aError is thrown");107userErrorThrown = true;108}109110try {111throw new location001aThrowable(); // userThrowableLocation112} catch (location001aThrowable e) { // <= expected catch location due to evaluation of 4740123. // userThrowableCatchLocation113log.display("location001aThrowable is thrown");114userThrowableThrown = true;115}116117try {118int i = Integer.parseInt("foo");119} catch (NumberFormatException e) { // <= expected catch location due to evaluation of 4740123. // userThrowableCatchLocation120log.display("NumberFormatException is thrown");121javaExceptionThrown = true;122}123124try {125raiseStackOverflow();126} catch (StackOverflowError e) { // <= expected catch location due to evaluation of 4740123. // javaErrorCatchLocation127log.display("StackOverflowError is thrown");128javaErrorThrown = true;129}130131} catch (Throwable e) {132log.complain("Unexpected Throwable: " + e.getMessage());133e.printStackTrace();134if (e instanceof ThreadDeath) {135throw e;136}137}138139// check that all exceptions are thrown140boolean thrown = true;141if (!userExceptionThrown) {142log.complain("TEST BUG: user exception NOT thrown");143thrown = false;144}145if (!userErrorThrown) {146log.complain("TEST BUG: user error NOT thrown");147thrown = false;148}149if (!userThrowableThrown) {150log.complain("TEST BUG: user Throwable NOT thrown");151thrown = false;152}153if (!javaExceptionThrown) {154log.complain("TEST BUG: java exception NOT thrown");155thrown = false;156}157if (!javaErrorThrown) {158log.complain("TEST BUG: java error NOT thrown");159thrown = false;160}161162// notify debugger whether all exceptions thrown or not163if (thrown) {164pipe.println(COMMAND_DONE);165} else {166pipe.println(COMMAND_ERROR);167}168169// wait for command <QUIT> from debugger and exit170command = pipe.readln();171if (!command.equals(COMMAND_QUIT)) {172log.complain("TEST BUG: unknown command: " + command);173return FAILED;174}175176return PASSED;177}178179private void raiseStackOverflow () {180raiseStackOverflow();181}182}183184class location001aException extends Exception {}185186class location001aError extends Error {}187188class location001aThrowable extends Throwable {}189190191