Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/EventRequestManager/createAccessWatchpointRequest/craccwtchpreq002.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.createAccessWatchpointRequest;2425import com.sun.jdi.VirtualMachine;26import com.sun.jdi.Field;27import com.sun.jdi.request.AccessWatchpointRequest;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.createAccessWatchpointRequest()</b>39* properly throws <code>NullPointerException</code> - if field is null.40*/41public class craccwtchpreq002 {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.createAccessWatchpointRequest.craccwtchpreq002t";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 craccwtchpreq002().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);67AccessWatchpointRequest awpRequest;68String cmd;69Field fld = null;7071debuggee = binder.bindToDebugee(DEBUGGEE_CLASS);72pipe = debuggee.createIOPipe();73debuggee.redirectStderr(log, "craccwtchpreq002t.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}8384if ( !vm.canWatchFieldAccess() ) {85log.display(" TEST CANCELLED due to: vm.canWatchFieldAccess() == false");86return quitDebuggee(PASSED);87}8889// Trying to create AccessWatchpointRequest for null Field parameter90try {91awpRequest =92erManager.createAccessWatchpointRequest(fld);93} catch (NullPointerException e) {94log.display("TEST PASSED: EventRequestManager.createAccessWatchpointRequest() throws expected "95+ e);96return quitDebuggee(PASSED);97} catch(VMMismatchException e) {98log.complain("TEST FAILED: EventRequestManager.createAccessWatchpointRequest() throws unexpected "99+ e + "\n\tbut it should throw NullPointerException for a null field");100return quitDebuggee(FAILED);101} catch(UnsupportedOperationException e) { // specified only in jdk1.4102log.complain("WARNING: test has no result. EventRequestManager.createAccessWatchpointRequest() throws "103+ e);104return quitDebuggee(PASSED);105}106log.complain("TEST FAILED: EventRequestManager.createAccessWatchpointRequest successfully done,\n\t"107+ "but it should throw NullPointerException for a null field");108return quitDebuggee(FAILED);109}110111private int quitDebuggee(int stat) {112pipe.println(COMMAND_QUIT);113debuggee.waitFor();114return stat;115}116}117118119