jdk/src/share/classes/com/sun/beans/finder/MethodFinder.java
Print this page
*** 23,40 ****
* questions.
*/
package com.sun.beans.finder;
import com.sun.beans.TypeResolver;
! import com.sun.beans.WeakCache;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.Arrays;
import static sun.reflect.misc.ReflectUtil.isPackageAccessible;
/**
* This utility class provides {@code static} methods
* to find a public method with specified name and parameter types
--- 23,41 ----
* questions.
*/
package com.sun.beans.finder;
import com.sun.beans.TypeResolver;
! import com.sun.beans.util.Cache;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.Arrays;
+ import static com.sun.beans.util.Cache.Kind.SOFT;
import static sun.reflect.misc.ReflectUtil.isPackageAccessible;
/**
* This utility class provides {@code static} methods
* to find a public method with specified name and parameter types
*** 43,53 ****
* @since 1.7
*
* @author Sergey A. Malenkov
*/
public final class MethodFinder extends AbstractFinder<Method> {
! private static final WeakCache<Signature, Method> CACHE = new WeakCache<Signature, Method>();
/**
* Finds public method (static or non-static)
* that is accessible from public class.
*
--- 44,65 ----
* @since 1.7
*
* @author Sergey A. Malenkov
*/
public final class MethodFinder extends AbstractFinder<Method> {
! private static final Cache<Signature, Method> CACHE = new Cache<Signature, Method>(SOFT, SOFT) {
! @Override
! public Method create(Signature signature) {
! try {
! MethodFinder finder = new MethodFinder(signature.getName(), signature.getArgs());
! return findAccessibleMethod(finder.find(signature.getType().getMethods()));
! }
! catch (Exception exception) {
! throw new SignatureException(exception);
! }
! }
! };
/**
* Finds public method (static or non-static)
* that is accessible from public class.
*
*** 63,82 ****
throw new IllegalArgumentException("Method name is not set");
}
PrimitiveWrapperMap.replacePrimitivesWithWrappers(args);
Signature signature = new Signature(type, name, args);
Method method = CACHE.get(signature);
! boolean cached = method != null;
! if (cached && isPackageAccessible(method.getDeclaringClass())) {
! return method;
! }
! method = findAccessibleMethod(new MethodFinder(name, args).find(type.getMethods()));
! if (!cached) {
! CACHE.put(signature, method);
}
- return method;
}
/**
* Finds public non-static method
* that is accessible from public class.
--- 75,91 ----
throw new IllegalArgumentException("Method name is not set");
}
PrimitiveWrapperMap.replacePrimitivesWithWrappers(args);
Signature signature = new Signature(type, name, args);
+ try {
Method method = CACHE.get(signature);
! return (method == null) || isPackageAccessible(method.getDeclaringClass()) ? method : CACHE.create(signature);
! }
! catch (SignatureException exception) {
! throw exception.toNoSuchMethodException("Method '" + name + "' is not found");
}
}
/**
* Finds public non-static method
* that is accessible from public class.