CauseExceptionTest.java revision 9330:8b1f1c2a400f
145501Sjdp/* 262801Sjdp * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. 345501Sjdp * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 445501Sjdp * 545501Sjdp * This code is free software; you can redistribute it and/or modify it 645501Sjdp * under the terms of the GNU General Public License version 2 only, as 745501Sjdp * published by the Free Software Foundation. 845501Sjdp * 945501Sjdp * This code is distributed in the hope that it will be useful, but WITHOUT 1045501Sjdp * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1145501Sjdp * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1245501Sjdp * version 2 for more details (a copy is included in the LICENSE file that 1345501Sjdp * accompanied this code). 1445501Sjdp * 1545501Sjdp * You should have received a copy of the GNU General Public License version 1645501Sjdp * 2 along with this work; if not, write to the Free Software Foundation, 1745501Sjdp * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1845501Sjdp * 1945501Sjdp * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2045501Sjdp * or visit www.oracle.com if you need additional information or have any 2145501Sjdp * questions. 2245501Sjdp */ 2345501Sjdp 2445501Sjdp/* 2545501Sjdp * @test 2650476Speter * @bug 6869617 2745501Sjdp * @summary ScriptEngine bug : ScriptException cause not set (with fix) 2845501Sjdp */ 2945501Sjdp 3045501Sjdpimport javax.script.*; 3145501Sjdpimport java.io.*; 32115396Skan 33115396Skanpublic class CauseExceptionTest { 34115396Skan public static void main(String[] args) throws ScriptException, NoSuchMethodException { 3585004Sdfr ScriptEngineManager sem = new ScriptEngineManager(); 3685004Sdfr ScriptEngine engine = sem.getEngineByName("nashorn"); 3745501Sjdp if (engine == null) { 3845501Sjdp System.out.println("Warning: No js engine found; test vacuously passes."); 3945501Sjdp return; 4045501Sjdp } 4148205Sjdp engine.eval("function hello_world() { print('hello world'); throw 'out of here'; } "); 4285004Sdfr Invocable invocable = (Invocable) engine; 4385004Sdfr try { 44107071Stmm invocable.invokeFunction("hello_world", (Object[])null); 45107071Stmm } catch (ScriptException se) { 4685004Sdfr Throwable cause = se.getCause(); 47157220Sdes if (cause == null) { 4885004Sdfr throw new RuntimeException("null cause"); 4985004Sdfr } 50157220Sdes System.out.println(cause); 5185004Sdfr } 5285004Sdfr } 5385004Sdfr}; 5448205Sjdp