You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by ah...@apache.org on 2019/09/21 14:59:59 UTC
[isis] branch v2 updated: ISIS-2158: _MethodCache made threadsafe,
also only lookup public methods
This is an automated email from the ASF dual-hosted git repository.
ahuber pushed a commit to branch v2
in repository https://gitbox.apache.org/repos/asf/isis.git
The following commit(s) were added to refs/heads/v2 by this push:
new 63a55e3 ISIS-2158: _MethodCache made threadsafe, also only lookup public methods
63a55e3 is described below
commit 63a55e3ed782a215d1f6c3e190c634db20defd08
Author: Andi Huber <ah...@apache.org>
AuthorDate: Sat Sep 21 16:59:50 2019 +0200
ISIS-2158: _MethodCache made threadsafe, also only lookup public methods
---
.../commons/internal/reflection/_MethodCache.java | 29 +++++++++++++++++++---
1 file changed, 25 insertions(+), 4 deletions(-)
diff --git a/core/commons/src/main/java/org/apache/isis/commons/internal/reflection/_MethodCache.java b/core/commons/src/main/java/org/apache/isis/commons/internal/reflection/_MethodCache.java
index 14a4c5f..3ca0acc 100644
--- a/core/commons/src/main/java/org/apache/isis/commons/internal/reflection/_MethodCache.java
+++ b/core/commons/src/main/java/org/apache/isis/commons/internal/reflection/_MethodCache.java
@@ -28,15 +28,36 @@ import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.val;
+/**
+ * <h1>- internal use only -</h1>
+ * <p>
+ * JDK reflection API has no Class.getMethod(name, ...) variant that does not produce an expensive
+ * stack-trace, when no such method exists.
+ *
+ * @apiNote thread-save
+ *
+ * </p>
+ * <p>
+ * <b>WARNING</b>: Do <b>NOT</b> use any of the classes provided by this package! <br/>
+ * These may be changed or removed without notice!
+ * </p>
+ * @since 2.0
+ */
public final class _MethodCache {
+ /**
+ * A drop-in replacement for {@link Class#getMethod(String, Class...)} that does not throw
+ * a {@link ClassNotFoundException}
+ */
public Method lookupMethod(Class<?> type, String name, Class<?>[] paramTypes) {
- if(!inspectedTypes.contains(type)) {
- for(val method : type.getDeclaredMethods()) {
- methodsByKey.put(Key.of(type, method), method);
+ synchronized(inspectedTypes) {
+ if(!inspectedTypes.contains(type)) {
+ for(val method : type.getMethods()) {
+ methodsByKey.put(Key.of(type, method), method);
+ }
+ inspectedTypes.add(type);
}
- inspectedTypes.add(type);
}
return methodsByKey.get(Key.of(type, name, nullify(paramTypes)));