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.BreakpointRequest._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 import java.util.*;
34 
35 /**
36  * The test checks up the            <br>
37  *  - <code>addThreadFilter</code>,  <br>
38  *  - <code>addInstanceFilter</code> <br>
39  * methods with <code>null</code> argument value.
40  * In any cases <code>NullPointerException</code> is expected.
41  */
42 public class filters001 {
43 
44     private final static String prefix = "nsk.jdi.BreakpointRequest._bounds_.";
45     private final static String debuggerName = prefix + "filters001";
46     private final static String debugeeName = debuggerName + "a";
47 
48     private static int exitStatus;
49     private static Log log;
50     private static Debugee debugee;
51     private static String classToCheck = prefix + filters001a.classToCheck;
52     private static String indent = "                  : ";
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         ReferenceType debugeeRef = debugee.classByName(debugeeName);
86         ReferenceType checkedClsRef = debugee.classByName(classToCheck);
87 
88         display("");
89         display(">>>" + filters001a.objName);
90         display("----------------------");
91         Field field = debugeeRef.fieldByName(filters001a.objName);
92         Value val = debugeeRef.getValue(field);
93 
94         BreakpointRequest request = debugee.setBreakpoint(checkedClsRef,
95                                                     filters001a.brkptMethodName,
96                                                     filters001a.brkptLineNumber);
97 
98         display("");
99         addThreadFilter(request, (ThreadReference )val);
100         display("");
101         addInstanceFilter(request, (ObjectReference )val);
102 
103         display("");
104         debugee.quit();
105     }
106 
addThreadFilter(BreakpointRequest request, ThreadReference thread)107     private void addThreadFilter(BreakpointRequest request, ThreadReference thread) {
108 
109         display("addThreadFilter   :ThreadReference> null");
110         try {
111             request.addThreadFilter(thread);
112             complain("*****NullPointerException is not thrown");
113             exitStatus = Consts.TEST_FAILED;
114         } catch (NullPointerException e) {
115             display("!!!Expected " + e);
116         } catch (Exception e) {
117             complain("*****Unexpected " + e);
118             exitStatus = Consts.TEST_FAILED;
119         }
120     }
121 
addInstanceFilter(BreakpointRequest request, ObjectReference instance)122     private void addInstanceFilter(BreakpointRequest request,
123                                                 ObjectReference instance) {
124 
125         display("addInstanceFilter :ObjectReference> null");
126 
127         try {
128             request.addInstanceFilter(instance);
129             complain("*****NullPointerException is not thrown");
130             exitStatus = Consts.TEST_FAILED;
131         } catch (NullPointerException e) {
132             display("!!!Expected " + e);
133         } catch (Exception e) {
134             complain("*****Unexpected " + e);
135             exitStatus = Consts.TEST_FAILED;
136         }
137     }
138 }
139