1 /* 2 * Copyright (c) 2002, 2018, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 package nsk.jdi.MethodEntryRequest._bounds_; 25 26 import nsk.share.*; 27 import nsk.share.jdi.*; 28 29 import com.sun.jdi.*; 30 import com.sun.jdi.request.*; 31 32 import java.io.*; 33 34 /** 35 * The test checks up the <br> 36 * - addThreadFilter(ThreadReference) <br> 37 * - addInstanceFilter(ObjectReference) <br> 38 * - addClassFilter(ReferenceType) <br> 39 * - addClassFilter(String) <br> 40 * - addClassExclusionFilter(String) <br> 41 * methods with <code>null</code> argument value. 42 * In any cases <code>NullPointerException</code> is expected. 43 */ 44 public class filters001 { 45 46 private final static String prefix = "nsk.jdi.MethodEntryRequest._bounds_."; 47 private final static String debuggerName = prefix + "filters001"; 48 private final static String debugeeName = debuggerName + "a"; 49 50 private static int exitStatus; 51 private static Log log; 52 private static Debugee debugee; 53 display(String msg)54 private static void display(String msg) { 55 log.display("debugger> " + msg); 56 } 57 complain(String msg)58 private static void complain(String msg) { 59 log.complain("debugger FAILURE> " + msg + "\n"); 60 } 61 main(String argv[])62 public static void main(String argv[]) { 63 System.exit(Consts.JCK_STATUS_BASE + run(argv, System.out)); 64 } 65 run(String argv[], PrintStream out)66 public static int run(String argv[], PrintStream out) { 67 68 exitStatus = Consts.TEST_PASSED; 69 70 filters001 thisTest = new filters001(); 71 72 ArgumentHandler argHandler = new ArgumentHandler(argv); 73 log = new Log(out, argHandler); 74 75 debugee = Debugee.prepareDebugee(argHandler, log, debugeeName); 76 77 thisTest.execTest(); 78 display("execTest finished. exitStatus = " + exitStatus); 79 80 return exitStatus; 81 } 82 execTest()83 private void execTest() { 84 85 display(""); 86 display(">>>creating MethodEntryRequest"); 87 88 MethodEntryRequest request = 89 debugee.getEventRequestManager().createMethodEntryRequest(); 90 91 display(""); 92 addThreadFilter(request, null); 93 94 display(""); 95 addInstanceFilter(request, null); 96 97 display(""); 98 addClassFilter(request, (ReferenceType )null); 99 100 display(""); 101 addClassFilter(request, (String )null); 102 103 display(""); 104 addClassExclusionFilter(request, (String )null); 105 106 display(""); 107 debugee.quit(); 108 } 109 addThreadFilter(MethodEntryRequest request, ThreadReference thread)110 private void addThreadFilter(MethodEntryRequest request, ThreadReference thread) { 111 String tmp = "addThreadFilter :thread name> "; 112 tmp += (thread == null) ? "<null>" : thread.name(); 113 display(tmp); 114 115 try { 116 request.addThreadFilter(thread); 117 if (thread==null){ 118 complain("*****NullPointerException is not thrown"); 119 exitStatus = Consts.TEST_FAILED; 120 } 121 } catch (NullPointerException e) { 122 if (thread == null){ 123 display("!!!Expected " + e); 124 } else { 125 complain("*****Unexpected " + e); 126 exitStatus = Consts.TEST_FAILED; 127 } 128 } catch (Exception e) { 129 complain("Unexpected " + e); 130 exitStatus = Consts.TEST_FAILED; 131 } 132 } 133 addInstanceFilter(MethodEntryRequest request, ObjectReference instance)134 private void addInstanceFilter(MethodEntryRequest request, 135 ObjectReference instance) { 136 String tmp = "addInstanceFilter :object value> "; 137 tmp += (instance == null) ? "<null>" : instance.toString(); 138 display(tmp); 139 140 try { 141 request.addInstanceFilter(instance); 142 if (instance==null){ 143 complain("*****NullPointerException is not thrown"); 144 exitStatus = Consts.TEST_FAILED; 145 } 146 } catch (NullPointerException e) { 147 if (instance == null){ 148 display("!!!Expected " + e); 149 } else { 150 complain("*****Unexpected " + e); 151 exitStatus = Consts.TEST_FAILED; 152 } 153 } catch (Exception e) { 154 complain("Unexpected " + e); 155 exitStatus = Consts.TEST_FAILED; 156 } 157 } 158 addClassFilter(MethodEntryRequest request, ReferenceType refType)159 private void addClassFilter(MethodEntryRequest request, ReferenceType refType) { 160 161 display("addClassFilter :ReferenceType> <" + refType + ">"); 162 163 try { 164 request.addClassFilter(refType); 165 if (refType==null){ 166 complain("*****NullPointerException is not thrown"); 167 exitStatus = Consts.TEST_FAILED; 168 } 169 } catch (NullPointerException e) { 170 if (refType==null){ 171 display("!!!Expected " + e); 172 } else { 173 complain("*****Unexpected " + e); 174 exitStatus = Consts.TEST_FAILED; 175 } 176 } catch (Exception e) { 177 complain("*****Unexpected " + e); 178 exitStatus = Consts.TEST_FAILED; 179 } 180 } 181 addClassFilter(MethodEntryRequest request, String classPattern)182 private void addClassFilter(MethodEntryRequest request, String classPattern) { 183 184 display("addClassFilter :classPattern> <" + classPattern + ">"); 185 try { 186 request.addClassFilter(classPattern); 187 if (classPattern==null){ 188 complain("*****NullPointerException is not thrown"); 189 exitStatus = Consts.TEST_FAILED; 190 } 191 } catch (NullPointerException e) { 192 if (classPattern==null){ 193 display("!!!Expected " + e); 194 } else { 195 complain("*****Unexpected " + e); 196 exitStatus = Consts.TEST_FAILED; 197 } 198 } catch (Exception e) { 199 complain("*****Unexpected " + e); 200 exitStatus = Consts.TEST_FAILED; 201 } 202 } 203 addClassExclusionFilter(MethodEntryRequest request, String classPattern)204 private void addClassExclusionFilter(MethodEntryRequest request, 205 String classPattern) { 206 display("addExclusionClassFilter :classPattern> <" + classPattern + ">"); 207 try { 208 request.addClassExclusionFilter(classPattern); 209 if (classPattern==null){ 210 complain("*****NullPointerException is not thrown"); 211 exitStatus = Consts.TEST_FAILED; 212 } 213 } catch (NullPointerException e) { 214 if (classPattern==null){ 215 display("!!!Expected " + e); 216 } else { 217 complain("*****Unexpected " + e); 218 exitStatus = Consts.TEST_FAILED; 219 } 220 } catch (Exception e) { 221 complain("*****Unexpected " + e); 222 exitStatus = Consts.TEST_FAILED; 223 } 224 } 225 226 } 227