/* * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ /* * @test * @run main BadClassFiles * @summary The reflection API should throw the correct exceptions. */ import java.lang.Class; import java.lang.reflect.Method; import java.lang.reflect.Parameter; import java.lang.reflect.MalformedParametersException; public class BadClassFiles { private int errors = 0; private final Class[] classes = { EmptyName.class, BadModifiers.class, BadNameIndex.class, NameIndexOutOfBounds.class, // Name with . BadName1.class, // Name with [ BadName2.class, // Name with ; BadName3.class, // Name with / BadName4.class, // Name with single unicode backspace BadName5.class, // Name with a backspace that becomes empty because of it. BadName6.class }; public static void main(String... args) throws NoSuchMethodException { new BadClassFiles().run(); } public void assertBadParameters(Class cls) throws NoSuchMethodException { try { System.err.println("Trying " + cls); final Method method = cls.getMethod("m", int.class, int.class); final Parameter[] params = method.getParameters(); System.err.println("Name " + params[0].getName()); System.err.println("Did not see expected exception"); errors++; } catch(MalformedParametersException e) { System.err.println("Expected exception seen"); } } public void run() throws NoSuchMethodException { for (Class cls : classes) assertBadParameters(cls); if (errors != 0) throw new RuntimeException(errors + " errors in test"); } }