1 /* 2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 25 /* 26 * @test 27 * @bug 8010117 28 * @summary Test CallerSensitiveFinder to find missing annotation 29 * @modules java.base/sun.reflect 30 * jdk.jdeps/com.sun.tools.classfile 31 * jdk.jdeps/com.sun.tools.jdeps 32 * @modules java.base/sun.reflect 33 * @compile -XDignore.symbol.file MissingCallerSensitive.java 34 * @build CallerSensitiveFinder 35 * @run main MissingCallerSensitive 36 */ 37 38 import java.nio.file.Path; 39 import java.nio.file.Paths; 40 import java.util.*; 41 import java.util.stream.Stream; 42 43 public class MissingCallerSensitive { 44 public static void main(String[] args) throws Exception { 45 String testclasses = System.getProperty("test.classes", "."); 46 47 Stream<Path> classes = Stream.of(Paths.get(testclasses, "MissingCallerSensitive.class")); 48 49 CallerSensitiveFinder csfinder = new CallerSensitiveFinder(); 50 List<String> errors = csfinder.run(classes); 51 if (errors.size() != 1) { 52 throw new RuntimeException("Unexpected number of methods found: " + errors.size()); 53 } 54 String m = errors.get(0); 55 if (!m.startsWith("MissingCallerSensitive#missingCallerSensitiveAnnotation")) { 56 throw new RuntimeException("Unexpected method missing annotation: " + m); 57 } 58 } 59 60 @sun.reflect.CallerSensitive 61 public ClassLoader getCallerLoader() { 62 Class<?> c = sun.reflect.Reflection.getCallerClass(); 63 return c.getClassLoader(); 64 } 65 66 public ClassLoader missingCallerSensitiveAnnotation() { 67 Class<?> c = sun.reflect.Reflection.getCallerClass(); 68 return c.getClassLoader(); 69 } 70 }