Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/lang/reflect/Generics/Probe.java
38828 views
/*1* Copyright (c) 2004, 2013, 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 5003916 6704655 6873951 6476261 800492826* @summary Testing parsing of signatures attributes of nested classes27* @author Joseph D. Darcy28*/2930import java.lang.reflect.*;31import java.lang.annotation.*;32import java.util.*;33import static java.util.Arrays.*;3435@Classes({"java.util.concurrent.FutureTask",36"java.util.concurrent.ConcurrentHashMap$EntryIterator",37"java.util.concurrent.ConcurrentHashMap$KeyIterator",38"java.util.concurrent.ConcurrentHashMap$ValueIterator",39"java.util.AbstractList$ListItr",40"java.util.EnumMap$EntryIterator",41"java.util.EnumMap$KeyIterator",42"java.util.EnumMap$ValueIterator",43"java.util.IdentityHashMap$EntryIterator",44"java.util.IdentityHashMap$KeyIterator",45"java.util.IdentityHashMap$ValueIterator",46"java.util.WeakHashMap$EntryIterator",47"java.util.WeakHashMap$KeyIterator",48"java.util.WeakHashMap$ValueIterator",49"java.util.HashMap$EntryIterator",50"java.util.HashMap$KeyIterator",51"java.util.HashMap$ValueIterator",52"java.util.LinkedHashMap$LinkedEntryIterator",53"java.util.LinkedHashMap$LinkedKeyIterator",54"java.util.LinkedHashMap$LinkedValueIterator"})55public class Probe {56public static void main (String... args) throws Throwable {57Classes classesAnnotation = (Probe.class).getAnnotation(Classes.class);58List<String> names = new ArrayList<>(asList(classesAnnotation.value()));5960int errs = 0;61for(String name: names) {62System.out.println("\nCLASS " + name);63Class c = Class.forName(name, false, null);64errs += probe(c);65System.out.println(errs == 0 ? " ok" : " ERRORS:" + errs);66}6768if (errs > 0 )69throw new RuntimeException("Errors during probing.");70}7172static int probe (Class c) {73int errs = 0;7475try {76c.getTypeParameters();77c.getGenericSuperclass();78c.getGenericInterfaces();79} catch (Throwable t) {80errs++;81System.err.println(t);82}8384Field[] fields = c.getDeclaredFields();85if (fields != null)86for(Field field: fields) {87try {88field.getGenericType();89} catch (Throwable t) {90errs++;91System.err.println("FIELD " + field);92System.err.println(t);93}94}9596Method[] methods = c.getDeclaredMethods();97if (methods != null)98for(Method method: methods) {99try {100method.getTypeParameters();101method.getGenericReturnType();102method.getGenericParameterTypes();103method.getGenericExceptionTypes();104} catch (Throwable t) {105errs++;106System.err.println("METHOD " + method);107System.err.println(t);108}109}110111Constructor[] ctors = c.getDeclaredConstructors();112if (ctors != null)113for(Constructor ctor: ctors) {114try {115ctor.getTypeParameters();116ctor.getGenericParameterTypes();117ctor.getGenericExceptionTypes();118} catch (Throwable t) {119errs++;120System.err.println("CONSTRUCTOR " + ctor);121System.err.println(t);122}123}124125return errs;126}127}128129@Retention(RetentionPolicy.RUNTIME)130@interface Classes {131String [] value(); // list of classes to probe132}133134135