Path: blob/master/test/hotspot/jtreg/vmTestbase/vm/mlvm/share/ExceptionsOptionObjectFactory.java
41155 views
/*1* Copyright (c) 2014, 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*/2223package vm.mlvm.share;2425import java.util.List;26import java.util.ArrayList;27import vm.share.options.OptionObjectFactory;28import java.util.regex.Pattern;2930/**31* Implementation of vm.share.options.OptionObjectFactory interface.32* Parses the comma-separated list of exception class names.33*34* @see vm.mlvm.share.MlvmTest35* @see vm.mlvm.share.MlvmTestExecutor#launch(Class<?> testClass, Object[] constructorArgs)36*37*/3839public class ExceptionsOptionObjectFactory implements OptionObjectFactory<List<Class<? extends Throwable>>> {4041private static final String DESCRIPTION = "list of exception class names separated by comma";4243@Override44public String getPlaceholder() {45return DESCRIPTION;46}4748@Override49public String getDescription() {50return DESCRIPTION;51}5253@Override54public String getParameterDescription(String param) {55return "exception of type " + param;56}5758@Override59public String[] getPossibleValues() {60return new String[] { Throwable.class.getName() };61}6263@Override64public String getDefaultValue() {65return "";66}6768@Override69public List<Class<? extends Throwable>> getObject(String classNameList) {70List<Class<? extends Throwable>> result = new ArrayList<>();71classNameList = classNameList.trim();7273if (!classNameList.isEmpty()) {74for (String className : classNameList.split(",")) {75result.add(getClassFor(className.trim()));76}77}7879return result;80}8182private static Class<? extends Throwable> getClassFor(String className) {83try {84return Class.forName(className).asSubclass(Throwable.class);85} catch (ClassNotFoundException e) {86throw new RuntimeException("Cannot find class '" + className + "'", e);87} catch (ClassCastException e) {88throw new RuntimeException("Subclass of " + Throwable.class.getName() + " should be specified. Cannot cast '" + className + "' to the Throwable", e);89}90}91}929394