1 /*
2  * Copyright (c) 2016, 2019, 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 8149743
27  * @summary crash when adding a breakpoint after redefining to add a private static method
28  * @comment converted from test/jdk/com/sun/jdi/RedefineAddPrivateMethod.sh
29  *
30  * @library /test/lib
31  * @compile -g RedefineAddPrivateMethod.java
32  * @run main/othervm RedefineAddPrivateMethod
33  */
34 
35 import jdk.test.lib.process.OutputAnalyzer;
36 import lib.jdb.JdbCommand;
37 import lib.jdb.JdbTest;
38 
39 class RedefineAddPrivateMethodTarg {
main(String[] args)40     static public void main(String[] args) {
41         System.out.println("@1 breakpoint");
42         System.out.println("@2 breakpoint");
43     }
44 
45     // @1 uncomment private static void test() {}
46 }
47 
48 public class RedefineAddPrivateMethod extends JdbTest {
49     static private final String ALLOW_ADD_DELETE_OPTION = "-XX:+AllowRedefinitionToAddDeleteMethods";
50 
main(String argv[])51     public static void main(String argv[]) {
52         RedefineAddPrivateMethod test = new RedefineAddPrivateMethod();
53         test.launchOptions.addVMOptions(ALLOW_ADD_DELETE_OPTION);
54         test.run();
55     }
56 
RedefineAddPrivateMethod()57     private RedefineAddPrivateMethod() {
58         super(DEBUGGEE_CLASS, SOURCE_FILE);
59     }
60 
61     private static final String DEBUGGEE_CLASS = RedefineAddPrivateMethodTarg.class.getName();
62     private static final String SOURCE_FILE = "RedefineAddPrivateMethod.java";
63 
64     @Override
runCases()65     protected void runCases() {
66         setBreakpoints(1);
67         jdb.command(JdbCommand.run());
68 
69         redefineClass(1, "-g");
70         // ensure "test()" method has been added successfully
71         execCommand(JdbCommand.eval(DEBUGGEE_CLASS + ".test()"))
72                 .shouldNotContain("ParseException");
73 
74         setBreakpoints(2);
75         jdb.command(JdbCommand.run());
76 
77         jdb.quit();
78 
79         new OutputAnalyzer(getDebuggeeOutput())
80                 .shouldNotContain("Internal exception:");
81     }
82 }
83