equal
deleted
inserted
replaced
1 /* |
1 /* |
2 * Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
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 |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
31 import java.lang.reflect.Modifier; |
31 import java.lang.reflect.Modifier; |
32 import java.lang.reflect.ParameterizedType; |
32 import java.lang.reflect.ParameterizedType; |
33 import java.lang.reflect.Type; |
33 import java.lang.reflect.Type; |
34 import java.util.Arrays; |
34 import java.util.Arrays; |
35 |
35 |
|
36 import static sun.reflect.misc.ReflectUtil.isPackageAccessible; |
|
37 |
36 /** |
38 /** |
37 * This utility class provides {@code static} methods |
39 * This utility class provides {@code static} methods |
38 * to find a public method with specified name and parameter types |
40 * to find a public method with specified name and parameter types |
39 * in specified class. |
41 * in specified class. |
40 * |
42 * |
118 * @throws NoSuchMethodException if method is not accessible or is not found |
120 * @throws NoSuchMethodException if method is not accessible or is not found |
119 * in specified superclass or interface |
121 * in specified superclass or interface |
120 */ |
122 */ |
121 public static Method findAccessibleMethod(Method method) throws NoSuchMethodException { |
123 public static Method findAccessibleMethod(Method method) throws NoSuchMethodException { |
122 Class<?> type = method.getDeclaringClass(); |
124 Class<?> type = method.getDeclaringClass(); |
123 if (Modifier.isPublic(type.getModifiers())) { |
125 if (Modifier.isPublic(type.getModifiers()) && isPackageAccessible(type)) { |
124 return method; |
126 return method; |
125 } |
127 } |
126 if (Modifier.isStatic(method.getModifiers())) { |
128 if (Modifier.isStatic(method.getModifiers())) { |
127 throw new NoSuchMethodException("Method '" + method.getName() + "' is not accessible"); |
129 throw new NoSuchMethodException("Method '" + method.getName() + "' is not accessible"); |
128 } |
130 } |