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 /*
25  * @test
26  * @bug 4690242 4695338
27  * @summary TTY: jdb throws NullPointerException when printing local variables
28  * @comment converted from test/jdk/com/sun/jdi/NullLocalVariable.sh
29  *
30  * @library /test/lib
31  * @compile -g NullLocalVariable.java
32  * @run main/othervm NullLocalVariable
33  */
34 
35 import jdk.test.lib.process.OutputAnalyzer;
36 import lib.jdb.JdbCommand;
37 import lib.jdb.JdbTest;
38 
39 class NullLocalVariableTarg {
main(String args[])40     public static final void main(String args[]) {
41         try {
42             System.out.println("hi!");               // @1 breakpoint
43         } catch (Exception e) {
44             e.printStackTrace();
45         } finally {
46             System.out.println("done");
47         }
48     }
49 }
50 
51 public class NullLocalVariable extends JdbTest {
main(String argv[])52     public static void main(String argv[]) {
53         new NullLocalVariable().run();
54     }
55 
NullLocalVariable()56     private NullLocalVariable() {
57         super(DEBUGGEE_CLASS);
58     }
59 
60     private static final String DEBUGGEE_CLASS = NullLocalVariableTarg.class.getName();
61 
62     @Override
runCases()63     protected void runCases() {
64         setBreakpointsFromTestSource("NullLocalVariable.java", 1);
65         // Run to breakpoint #1
66         jdb.command(JdbCommand.run());
67 
68         jdb.command(JdbCommand.next());
69         jdb.command(JdbCommand.next());
70         jdb.command(JdbCommand.locals());
71         jdb.contToExit(1);
72 
73         new OutputAnalyzer(getDebuggeeOutput())
74                 .shouldNotContain("Internal exception");
75     }
76 }
77