1 /*
2  * Copyright (c) 2016, 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 8160024
27  * @summary jdb returns invalid argument count if first parameter to Arrays.asList is null
28  * @comment converted from test/jdk/com/sun/jdi/EvalArraysAsList.sh
29  *
30  * @library /test/lib
31  * @build EvalArraysAsList
32  * @run main/othervm EvalArraysAsList
33  */
34 
35 import lib.jdb.JdbCommand;
36 import lib.jdb.JdbTest;
37 
38 /*
39  * The test checks if evaluation of the expression java.util.Arrays.asList(null, "a")
40  * works normally and does not throw an IllegalArgumentException.
41  */
42 class EvalArraysAsListTarg {
main(String[] args)43     public static void main(String[] args) {
44         java.util.List<Object> l = java.util.Arrays.asList(null, "a");
45         System.out.println("java.util.Arrays.asList(null, \"a\") returns: " + l);
46         return;    // @1 breakpoint
47     }
48 }
49 
50 
51 public class EvalArraysAsList extends JdbTest {
main(String argv[])52     public static void main(String argv[]) {
53         new EvalArraysAsList().run();
54     }
55 
EvalArraysAsList()56     private EvalArraysAsList() {
57         super(DEBUGGEE_CLASS);
58     }
59 
60     private static final String DEBUGGEE_CLASS = EvalArraysAsListTarg.class.getName();
61 
62     @Override
runCases()63     protected void runCases() {
64         setBreakpointsFromTestSource("EvalArraysAsList.java", 1);
65         // Run to breakpoint #1
66         jdb.command(JdbCommand.run());
67 
68         final String illegalArgumentException = "IllegalArgumentException";
69 
70         evalShouldNotContain("java.util.Arrays.asList(null, null)", illegalArgumentException);
71 
72         evalShouldNotContain("java.util.Arrays.asList(null, \"a\")", illegalArgumentException);
73 
74         evalShouldNotContain("java.util.Arrays.asList(\"a\", null)", illegalArgumentException);
75 
76         jdb.contToExit(1);
77     }
78 
79 }
80