Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/EventRequestManager/createBreakpointRequest/crbreakpreq002.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.EventRequestManager.createBreakpointRequest;2425import com.sun.jdi.VirtualMachine;26import com.sun.jdi.Location;27import com.sun.jdi.request.BreakpointRequest;28import com.sun.jdi.request.EventRequestManager;29import com.sun.jdi.VMMismatchException;30import java.io.*;3132import nsk.share.*;33import nsk.share.jpda.*;34import nsk.share.jdi.*;3536/**37* The test checks that the JDI method38* <b>com.sun.jdi.request.EventRequestManager.createBreakpointRequest()</b>39* properly throws <code>NullPointerException</code> - if location is null.40*/41public class crbreakpreq002 {42public static final int PASSED = 0;43public static final int FAILED = 2;44public static final int JCK_STATUS_BASE = 95;45static final String DEBUGGEE_CLASS =46"nsk.jdi.EventRequestManager.createBreakpointRequest.crbreakpreq002t";47static final String COMMAND_READY = "ready";48static final String COMMAND_QUIT = "quit";4950private ArgumentHandler argHandler;51private Log log;52private IOPipe pipe;53private Debugee debuggee;5455public static void main (String argv[]) {56System.exit(run(argv,System.out) + JCK_STATUS_BASE);57}5859public static int run(String argv[], PrintStream out) {60return new crbreakpreq002().runIt(argv, out);61}6263private int runIt(String args[], PrintStream out) {64argHandler = new ArgumentHandler(args);65log = new Log(out, argHandler);66Binder binder = new Binder(argHandler, log);67BreakpointRequest bpRequest;68String cmd;69Location loc = null;7071debuggee = binder.bindToDebugee(DEBUGGEE_CLASS);72pipe = debuggee.createIOPipe();73debuggee.redirectStderr(log, "crbreakpreq002t.err> ");74VirtualMachine vm = debuggee.VM();75EventRequestManager erManager = vm.eventRequestManager();76debuggee.resume();77cmd = pipe.readln();78if (!cmd.equals(COMMAND_READY)) {79log.complain("TEST BUG: unknown debuggee's command: "80+ cmd);81return quitDebuggee(FAILED);82}8384// Trying to create BreakpointRequest for a null Location parameter85try {86bpRequest =87erManager.createBreakpointRequest(loc);88} catch (NullPointerException e) {89log.display("TEST PASSED: EventRequestManager.createBreakpointRequest() throws expected "90+ e);91return quitDebuggee(PASSED);92} catch(VMMismatchException e) {93log.complain("TEST FAILED: EventRequestManager.createBreakpointRequest() throws unexpected "94+ e + "\n\tbut it should throw NullPointerException for a null location");95return quitDebuggee(FAILED);96} catch(UnsupportedOperationException e) { // specified only in jdk1.497log.complain("WARNING: test has no result. EventRequestManager.createBreakpointRequest() throws "98+ e);99return quitDebuggee(PASSED);100}101log.complain("TEST FAILED: EventRequestManager.createBreakpointRequest() successfully done,\n\t"102+ "but it should throw NullPointerException for a null location");103return quitDebuggee(FAILED);104}105106private int quitDebuggee(int stat) {107pipe.println(COMMAND_QUIT);108debuggee.waitFor();109return stat;110}111}112113114