Path: blob/master/test/jdk/tools/jlink/optimplugin/optim/ForNameTestCase.java
41153 views
/*1* Copyright (c) 2015, 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 optim;2425public class ForNameTestCase {26private static final String EXPECTED = "expected";27public static Class<?> forName() {28try {29Class<?> cl = Class.forName("java.lang.String");30return cl;31} catch (ClassNotFoundException |32IllegalArgumentException |33ClassCastException x) {34throw new InternalError(x);35}36}3738public static Class<?> forName0() throws ClassNotFoundException {39return Class.forName("java.lang.String");40}4142public static Class<?> forName1() throws Exception {43Class<?> clazz = null;44try {45clazz = Class.forName("java.lang.String");46} catch (ClassNotFoundException e) {47return null;48}49return clazz;50}5152public static void forNameException() throws Exception {53try {54Class.forName("java.lang.String");55throw new Exception(EXPECTED);56} catch (ClassNotFoundException e) {57return;58} catch (RuntimeException e) {59return;60}61}6263public static Class<?> forName2() throws Exception {64Class<?> clazz = null;65try {66clazz = Class.forName("java.lang.String");67try {68throw new Exception("das");69} catch (Exception ex) {70}71} catch (ClassNotFoundException e) {72return null;73}74return clazz;75}7677public static Class<?> forName3() throws Exception {78Class<?> clazz = null;79try {80return clazz = Class.forName("java.lang.String");81} catch (ClassNotFoundException e) {82return null;83}84}8586public static Class<?> forName4() throws Exception {87Class<?> clazz = null;88try {89clazz = Class.forName("java.lang.String");90} catch (ClassNotFoundException e) {91return null;92} catch (RuntimeException e) {93return null;94}95return clazz;96}9798public static Class<?> forName5() {99Class<?> clazz = null;100try {101clazz = Class.forName("java.lang.String");102} catch (ClassNotFoundException e) {103}104int i;105try {106i = 0;107} catch (Exception e) {108}109return clazz;110}111112public static Class<?> forName6() {113Class<?> clazz = null;114try {115return Class.forName("java.lang.String");116} catch (ClassNotFoundException e) {117}118119try {120// This one is removed because no more reachable when121// Class.forName is removed122int k = 0;123} catch (RuntimeException e) {124}125126int i;127try {128// This one is removed because no more reachable when129// Class.forName is removed130return Class.forName("TOTO");131} catch (ClassNotFoundException e) {132}133try {134// This one is removed because no more reachable when135// Class.forName is removed136return Class.forName("TOTO");137} catch (ClassNotFoundException e) {138}139try {140// This one is removed because no more reachable when141// Class.forName is removed142return Class.forName("TOTO");143} catch (ClassNotFoundException e) {144}145try {146// This one is removed because no more reachable when147// Class.forName is removed148return Class.forName("TOTO");149} catch (ClassNotFoundException e) {150}151return clazz;152}153154public static Class<?> forName7() {155Class<?> clazz = null;156try {157clazz = Class.forName("optim.AType");158} catch (ClassNotFoundException e) {159}160return clazz;161}162163public static Class<?> negativeforName() {164Class<?> clazz = null;165try {166clazz = Class.forName("jdk.internal.jimage.BasicImageReader");167} catch (ClassNotFoundException e) {168}169return clazz;170}171}172173174