author | coleenp |
Wed, 15 Nov 2017 08:14:31 -0500 | |
changeset 47894 | 352b17f62ff7 |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
46926
25ac5da6502e
8185108: JShell: NullPointerException when throwing exception with null message under local ExecutionControl
rfield
parents:
diff
changeset
|
1 |
/* |
25ac5da6502e
8185108: JShell: NullPointerException when throwing exception with null message under local ExecutionControl
rfield
parents:
diff
changeset
|
2 |
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. |
25ac5da6502e
8185108: JShell: NullPointerException when throwing exception with null message under local ExecutionControl
rfield
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
25ac5da6502e
8185108: JShell: NullPointerException when throwing exception with null message under local ExecutionControl
rfield
parents:
diff
changeset
|
4 |
* |
25ac5da6502e
8185108: JShell: NullPointerException when throwing exception with null message under local ExecutionControl
rfield
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
25ac5da6502e
8185108: JShell: NullPointerException when throwing exception with null message under local ExecutionControl
rfield
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
25ac5da6502e
8185108: JShell: NullPointerException when throwing exception with null message under local ExecutionControl
rfield
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
25ac5da6502e
8185108: JShell: NullPointerException when throwing exception with null message under local ExecutionControl
rfield
parents:
diff
changeset
|
8 |
* |
25ac5da6502e
8185108: JShell: NullPointerException when throwing exception with null message under local ExecutionControl
rfield
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
25ac5da6502e
8185108: JShell: NullPointerException when throwing exception with null message under local ExecutionControl
rfield
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
25ac5da6502e
8185108: JShell: NullPointerException when throwing exception with null message under local ExecutionControl
rfield
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
25ac5da6502e
8185108: JShell: NullPointerException when throwing exception with null message under local ExecutionControl
rfield
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
25ac5da6502e
8185108: JShell: NullPointerException when throwing exception with null message under local ExecutionControl
rfield
parents:
diff
changeset
|
13 |
* accompanied this code). |
25ac5da6502e
8185108: JShell: NullPointerException when throwing exception with null message under local ExecutionControl
rfield
parents:
diff
changeset
|
14 |
* |
25ac5da6502e
8185108: JShell: NullPointerException when throwing exception with null message under local ExecutionControl
rfield
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
25ac5da6502e
8185108: JShell: NullPointerException when throwing exception with null message under local ExecutionControl
rfield
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
25ac5da6502e
8185108: JShell: NullPointerException when throwing exception with null message under local ExecutionControl
rfield
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
25ac5da6502e
8185108: JShell: NullPointerException when throwing exception with null message under local ExecutionControl
rfield
parents:
diff
changeset
|
18 |
* |
25ac5da6502e
8185108: JShell: NullPointerException when throwing exception with null message under local ExecutionControl
rfield
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
25ac5da6502e
8185108: JShell: NullPointerException when throwing exception with null message under local ExecutionControl
rfield
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
25ac5da6502e
8185108: JShell: NullPointerException when throwing exception with null message under local ExecutionControl
rfield
parents:
diff
changeset
|
21 |
* questions. |
25ac5da6502e
8185108: JShell: NullPointerException when throwing exception with null message under local ExecutionControl
rfield
parents:
diff
changeset
|
22 |
*/ |
25ac5da6502e
8185108: JShell: NullPointerException when throwing exception with null message under local ExecutionControl
rfield
parents:
diff
changeset
|
23 |
|
25ac5da6502e
8185108: JShell: NullPointerException when throwing exception with null message under local ExecutionControl
rfield
parents:
diff
changeset
|
24 |
/* |
25ac5da6502e
8185108: JShell: NullPointerException when throwing exception with null message under local ExecutionControl
rfield
parents:
diff
changeset
|
25 |
* @test |
25ac5da6502e
8185108: JShell: NullPointerException when throwing exception with null message under local ExecutionControl
rfield
parents:
diff
changeset
|
26 |
* @bug 8185108 |
25ac5da6502e
8185108: JShell: NullPointerException when throwing exception with null message under local ExecutionControl
rfield
parents:
diff
changeset
|
27 |
* @summary Test exception().getMessage() in events returned by eval() |
25ac5da6502e
8185108: JShell: NullPointerException when throwing exception with null message under local ExecutionControl
rfield
parents:
diff
changeset
|
28 |
* @run testng ExceptionMessageTest |
25ac5da6502e
8185108: JShell: NullPointerException when throwing exception with null message under local ExecutionControl
rfield
parents:
diff
changeset
|
29 |
*/ |
25ac5da6502e
8185108: JShell: NullPointerException when throwing exception with null message under local ExecutionControl
rfield
parents:
diff
changeset
|
30 |
|
25ac5da6502e
8185108: JShell: NullPointerException when throwing exception with null message under local ExecutionControl
rfield
parents:
diff
changeset
|
31 |
import java.util.HashMap; |
25ac5da6502e
8185108: JShell: NullPointerException when throwing exception with null message under local ExecutionControl
rfield
parents:
diff
changeset
|
32 |
import java.util.Map; |
25ac5da6502e
8185108: JShell: NullPointerException when throwing exception with null message under local ExecutionControl
rfield
parents:
diff
changeset
|
33 |
import java.util.List; |
25ac5da6502e
8185108: JShell: NullPointerException when throwing exception with null message under local ExecutionControl
rfield
parents:
diff
changeset
|
34 |
|
25ac5da6502e
8185108: JShell: NullPointerException when throwing exception with null message under local ExecutionControl
rfield
parents:
diff
changeset
|
35 |
import jdk.jshell.JShell; |
25ac5da6502e
8185108: JShell: NullPointerException when throwing exception with null message under local ExecutionControl
rfield
parents:
diff
changeset
|
36 |
import jdk.jshell.SnippetEvent; |
25ac5da6502e
8185108: JShell: NullPointerException when throwing exception with null message under local ExecutionControl
rfield
parents:
diff
changeset
|
37 |
import jdk.jshell.execution.DirectExecutionControl; |
25ac5da6502e
8185108: JShell: NullPointerException when throwing exception with null message under local ExecutionControl
rfield
parents:
diff
changeset
|
38 |
import jdk.jshell.execution.JdiExecutionControlProvider; |
25ac5da6502e
8185108: JShell: NullPointerException when throwing exception with null message under local ExecutionControl
rfield
parents:
diff
changeset
|
39 |
import jdk.jshell.execution.LocalExecutionControlProvider; |
25ac5da6502e
8185108: JShell: NullPointerException when throwing exception with null message under local ExecutionControl
rfield
parents:
diff
changeset
|
40 |
import jdk.jshell.spi.ExecutionControl; |
25ac5da6502e
8185108: JShell: NullPointerException when throwing exception with null message under local ExecutionControl
rfield
parents:
diff
changeset
|
41 |
import jdk.jshell.spi.ExecutionControlProvider; |
25ac5da6502e
8185108: JShell: NullPointerException when throwing exception with null message under local ExecutionControl
rfield
parents:
diff
changeset
|
42 |
import jdk.jshell.spi.ExecutionEnv; |
25ac5da6502e
8185108: JShell: NullPointerException when throwing exception with null message under local ExecutionControl
rfield
parents:
diff
changeset
|
43 |
|
25ac5da6502e
8185108: JShell: NullPointerException when throwing exception with null message under local ExecutionControl
rfield
parents:
diff
changeset
|
44 |
import org.testng.annotations.DataProvider; |
25ac5da6502e
8185108: JShell: NullPointerException when throwing exception with null message under local ExecutionControl
rfield
parents:
diff
changeset
|
45 |
import org.testng.annotations.Test; |
25ac5da6502e
8185108: JShell: NullPointerException when throwing exception with null message under local ExecutionControl
rfield
parents:
diff
changeset
|
46 |
import static org.testng.Assert.assertEquals; |
25ac5da6502e
8185108: JShell: NullPointerException when throwing exception with null message under local ExecutionControl
rfield
parents:
diff
changeset
|
47 |
import static org.testng.Assert.assertTrue; |
25ac5da6502e
8185108: JShell: NullPointerException when throwing exception with null message under local ExecutionControl
rfield
parents:
diff
changeset
|
48 |
|
25ac5da6502e
8185108: JShell: NullPointerException when throwing exception with null message under local ExecutionControl
rfield
parents:
diff
changeset
|
49 |
@Test |
25ac5da6502e
8185108: JShell: NullPointerException when throwing exception with null message under local ExecutionControl
rfield
parents:
diff
changeset
|
50 |
public class ExceptionMessageTest { |
25ac5da6502e
8185108: JShell: NullPointerException when throwing exception with null message under local ExecutionControl
rfield
parents:
diff
changeset
|
51 |
|
25ac5da6502e
8185108: JShell: NullPointerException when throwing exception with null message under local ExecutionControl
rfield
parents:
diff
changeset
|
52 |
public void testDefaultEC() { |
25ac5da6502e
8185108: JShell: NullPointerException when throwing exception with null message under local ExecutionControl
rfield
parents:
diff
changeset
|
53 |
doTestCases(new JdiExecutionControlProvider(), "default"); |
25ac5da6502e
8185108: JShell: NullPointerException when throwing exception with null message under local ExecutionControl
rfield
parents:
diff
changeset
|
54 |
} |
25ac5da6502e
8185108: JShell: NullPointerException when throwing exception with null message under local ExecutionControl
rfield
parents:
diff
changeset
|
55 |
|
25ac5da6502e
8185108: JShell: NullPointerException when throwing exception with null message under local ExecutionControl
rfield
parents:
diff
changeset
|
56 |
public void testLocalEC() { |
25ac5da6502e
8185108: JShell: NullPointerException when throwing exception with null message under local ExecutionControl
rfield
parents:
diff
changeset
|
57 |
doTestCases(new LocalExecutionControlProvider(), "local"); |
25ac5da6502e
8185108: JShell: NullPointerException when throwing exception with null message under local ExecutionControl
rfield
parents:
diff
changeset
|
58 |
} |
25ac5da6502e
8185108: JShell: NullPointerException when throwing exception with null message under local ExecutionControl
rfield
parents:
diff
changeset
|
59 |
|
25ac5da6502e
8185108: JShell: NullPointerException when throwing exception with null message under local ExecutionControl
rfield
parents:
diff
changeset
|
60 |
public void testDirectEC() { |
25ac5da6502e
8185108: JShell: NullPointerException when throwing exception with null message under local ExecutionControl
rfield
parents:
diff
changeset
|
61 |
doTestCases(new ExecutionControlProvider() { |
25ac5da6502e
8185108: JShell: NullPointerException when throwing exception with null message under local ExecutionControl
rfield
parents:
diff
changeset
|
62 |
public ExecutionControl generate(ExecutionEnv env, Map<String, String> param) throws Throwable { |
25ac5da6502e
8185108: JShell: NullPointerException when throwing exception with null message under local ExecutionControl
rfield
parents:
diff
changeset
|
63 |
return new DirectExecutionControl(); |
25ac5da6502e
8185108: JShell: NullPointerException when throwing exception with null message under local ExecutionControl
rfield
parents:
diff
changeset
|
64 |
} |
25ac5da6502e
8185108: JShell: NullPointerException when throwing exception with null message under local ExecutionControl
rfield
parents:
diff
changeset
|
65 |
|
25ac5da6502e
8185108: JShell: NullPointerException when throwing exception with null message under local ExecutionControl
rfield
parents:
diff
changeset
|
66 |
public String name() { |
25ac5da6502e
8185108: JShell: NullPointerException when throwing exception with null message under local ExecutionControl
rfield
parents:
diff
changeset
|
67 |
return "direct"; |
25ac5da6502e
8185108: JShell: NullPointerException when throwing exception with null message under local ExecutionControl
rfield
parents:
diff
changeset
|
68 |
} |
25ac5da6502e
8185108: JShell: NullPointerException when throwing exception with null message under local ExecutionControl
rfield
parents:
diff
changeset
|
69 |
|
25ac5da6502e
8185108: JShell: NullPointerException when throwing exception with null message under local ExecutionControl
rfield
parents:
diff
changeset
|
70 |
}, "direct"); |
25ac5da6502e
8185108: JShell: NullPointerException when throwing exception with null message under local ExecutionControl
rfield
parents:
diff
changeset
|
71 |
} |
25ac5da6502e
8185108: JShell: NullPointerException when throwing exception with null message under local ExecutionControl
rfield
parents:
diff
changeset
|
72 |
|
25ac5da6502e
8185108: JShell: NullPointerException when throwing exception with null message under local ExecutionControl
rfield
parents:
diff
changeset
|
73 |
private JShell shell(ExecutionControlProvider ec) { |
25ac5da6502e
8185108: JShell: NullPointerException when throwing exception with null message under local ExecutionControl
rfield
parents:
diff
changeset
|
74 |
return JShell.builder().executionEngine(ec, new HashMap<>()).build(); |
25ac5da6502e
8185108: JShell: NullPointerException when throwing exception with null message under local ExecutionControl
rfield
parents:
diff
changeset
|
75 |
} |
25ac5da6502e
8185108: JShell: NullPointerException when throwing exception with null message under local ExecutionControl
rfield
parents:
diff
changeset
|
76 |
|
25ac5da6502e
8185108: JShell: NullPointerException when throwing exception with null message under local ExecutionControl
rfield
parents:
diff
changeset
|
77 |
private void doTestCases(ExecutionControlProvider ec, String label) { |
25ac5da6502e
8185108: JShell: NullPointerException when throwing exception with null message under local ExecutionControl
rfield
parents:
diff
changeset
|
78 |
JShell jshell = shell(ec); |
25ac5da6502e
8185108: JShell: NullPointerException when throwing exception with null message under local ExecutionControl
rfield
parents:
diff
changeset
|
79 |
doTest(jshell, label, "throw new java.io.IOException();", null); |
25ac5da6502e
8185108: JShell: NullPointerException when throwing exception with null message under local ExecutionControl
rfield
parents:
diff
changeset
|
80 |
doTest(jshell, label, "throw new java.io.IOException((String)null);", null); |
25ac5da6502e
8185108: JShell: NullPointerException when throwing exception with null message under local ExecutionControl
rfield
parents:
diff
changeset
|
81 |
doTest(jshell, label, "throw new java.io.IOException(\"\");", ""); |
25ac5da6502e
8185108: JShell: NullPointerException when throwing exception with null message under local ExecutionControl
rfield
parents:
diff
changeset
|
82 |
doTest(jshell, label, "throw new java.io.IOException(\"test\");", "test"); |
25ac5da6502e
8185108: JShell: NullPointerException when throwing exception with null message under local ExecutionControl
rfield
parents:
diff
changeset
|
83 |
} |
25ac5da6502e
8185108: JShell: NullPointerException when throwing exception with null message under local ExecutionControl
rfield
parents:
diff
changeset
|
84 |
|
25ac5da6502e
8185108: JShell: NullPointerException when throwing exception with null message under local ExecutionControl
rfield
parents:
diff
changeset
|
85 |
private void doTest(JShell jshell, String label, String code, String expected) { |
25ac5da6502e
8185108: JShell: NullPointerException when throwing exception with null message under local ExecutionControl
rfield
parents:
diff
changeset
|
86 |
List<SnippetEvent> result = jshell.eval(code); |
25ac5da6502e
8185108: JShell: NullPointerException when throwing exception with null message under local ExecutionControl
rfield
parents:
diff
changeset
|
87 |
assertEquals(result.size(), 1, "Expected only one event"); |
25ac5da6502e
8185108: JShell: NullPointerException when throwing exception with null message under local ExecutionControl
rfield
parents:
diff
changeset
|
88 |
SnippetEvent evt = result.get(0); |
25ac5da6502e
8185108: JShell: NullPointerException when throwing exception with null message under local ExecutionControl
rfield
parents:
diff
changeset
|
89 |
Exception exc = evt.exception(); |
25ac5da6502e
8185108: JShell: NullPointerException when throwing exception with null message under local ExecutionControl
rfield
parents:
diff
changeset
|
90 |
String out = exc.getMessage(); |
25ac5da6502e
8185108: JShell: NullPointerException when throwing exception with null message under local ExecutionControl
rfield
parents:
diff
changeset
|
91 |
assertEquals(out, expected, "Exception message not as expected: " + |
25ac5da6502e
8185108: JShell: NullPointerException when throwing exception with null message under local ExecutionControl
rfield
parents:
diff
changeset
|
92 |
label + " -- " + code); |
25ac5da6502e
8185108: JShell: NullPointerException when throwing exception with null message under local ExecutionControl
rfield
parents:
diff
changeset
|
93 |
} |
25ac5da6502e
8185108: JShell: NullPointerException when throwing exception with null message under local ExecutionControl
rfield
parents:
diff
changeset
|
94 |
} |