Path: blob/master/test/jdk/com/sun/jdi/CatchPatternTest.java
41152 views
/*1* Copyright (c) 2002, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 467183826* @summary TTY: surprising ExceptionSpec.resolveEventRequest() wildcard results27* @comment converted from test/jdk/com/sun/jdi/CatchPatternTest.sh28*29* @library /test/lib30* @build CatchPatternTest31* @run main/othervm CatchPatternTest32*/3334import jdk.test.lib.process.OutputAnalyzer;35import lib.jdb.JdbCommand;36import lib.jdb.JdbTest;3738class CatchPatternTestTarg {39public void bark(int i) {40System.out.println(" bark: " + i);41switch (i) {42case 0:43throw new IllegalArgumentException("IllegalArgumentException");44case 1:45throw new ArithmeticException("ArithmeticException");46case 2:47throw new IllegalMonitorStateException("IllegalMonitorStateException");48case 3:49throw new IndexOutOfBoundsException("IndexOutOfBoundsException");50default:51throw new Error("should not happen");52}53}54public void loop(int max) {55for (int i = 0; i <= max; i++) {56try {57bark(i);58} catch(RuntimeException re) {59System.out.println(" loop: " + re.getMessage() +60" caught and ignored.");61}62}63}64public void partOne() {65loop(2);66System.out.println("partOne completed");67}68public void partTwo() {69loop(3);70System.out.println("partTwo completed");71}72public static void main(String[] args) {73System.out.println("Howdy!");74CatchPatternTestTarg my = new CatchPatternTestTarg();75my.partOne();76my.partTwo();77System.out.println("Goodbye from CatchPatternTestTarg!");78}79}8081public class CatchPatternTest extends JdbTest {82public static void main(String argv[]) {83new CatchPatternTest().run();84}8586private CatchPatternTest() {87super(DEBUGGEE_CLASS);88}8990private static final String DEBUGGEE_CLASS = CatchPatternTestTarg.class.getName();9192@Override93protected void runCases() {94jdb.command(JdbCommand.stopIn(DEBUGGEE_CLASS, "main"));95jdb.command(JdbCommand.stopIn(DEBUGGEE_CLASS, "partTwo"));96jdb.command(JdbCommand.run());9798jdb.command(JdbCommand.ignore(JdbCommand.ExType.uncaught, "java.lang.Throwable"));99// Instead of matching java.lang.I* we use two more specific100// patterns here. The reason is to avoid matching IncompatibleClassChangeError101// (or the subclass NoSuchMethodError) thrown by the102// java.lang.invoke infrastructure.103jdb.command(JdbCommand.catch_(JdbCommand.ExType.all, "java.lang.Il*"));104jdb.command(JdbCommand.catch_(JdbCommand.ExType.all, "java.lang.Ind*"));105jdb.command(JdbCommand.cont());106jdb.command(JdbCommand.cont());107jdb.command(JdbCommand.cont());108jdb.command(JdbCommand.ignore(JdbCommand.ExType.all, "java.lang.Ind*"));109jdb.command(JdbCommand.ignore(JdbCommand.ExType.all, "java.lang.Il*"));110111jdb.contToExit(1);112113new OutputAnalyzer(getJdbOutput())114.shouldContain("Exception occurred: java.lang.IllegalArgumentException")115.shouldContain("Exception occurred: java.lang.IllegalMonitorStateException")116.shouldNotContain("Exception occurred: ArithmeticException")117.shouldNotContain("Exception occurred: IndexOutOfBoundsException")118.shouldNotContain("Exception occurred: IllegalStateException")119.shouldNotContain("should not happen");120new OutputAnalyzer(getDebuggeeOutput())121.shouldContain("partOne completed")122.shouldContain("partTwo completed");123}124125}126127128