[camel] branch master updated: CAMEL-14582: camel-bean - Optimize excluded methods

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[camel] branch master updated: CAMEL-14582: camel-bean - Optimize excluded methods

davsclaus-2
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/master by this push:
     new d4ef673  CAMEL-14582: camel-bean - Optimize excluded methods
d4ef673 is described below

commit d4ef6735148a5c4e2de94f0b588765e1fd4b09e0
Author: Claus Ibsen <[hidden email]>
AuthorDate: Mon Feb 17 19:14:18 2020 +0100

    CAMEL-14582: camel-bean - Optimize excluded methods
---
 .../org/apache/camel/component/bean/BeanInfo.java  | 30 ++++++----------------
 1 file changed, 8 insertions(+), 22 deletions(-)

diff --git a/components/camel-bean/src/main/java/org/apache/camel/component/bean/BeanInfo.java b/components/camel-bean/src/main/java/org/apache/camel/component/bean/BeanInfo.java
index 899b03e..297e806 100644
--- a/components/camel-bean/src/main/java/org/apache/camel/component/bean/BeanInfo.java
+++ b/components/camel-bean/src/main/java/org/apache/camel/component/bean/BeanInfo.java
@@ -19,7 +19,6 @@ package org.apache.camel.component.bean;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
-import java.lang.reflect.Proxy;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
@@ -62,7 +61,10 @@ import org.slf4j.LoggerFactory;
 public class BeanInfo {
     private static final Logger LOG = LoggerFactory.getLogger(BeanInfo.class);
     private static final String CGLIB_CLASS_SEPARATOR = "$$";
-    private static final List<Method> EXCLUDED_METHODS = new ArrayList<>();
+    private static final String[] EXCLUDED_METHOD_NAMES = new String[]{
+            "clone", "equals", "finalize", "getClass", "hashCode", "notify", "notifyAll", "wait", // java.lang.Object
+            "getInvocationHandler", "getProxyClass", "isProxyClass", "newProxyInstance" // java.lang.Proxy
+    };
     private final CamelContext camelContext;
     private final BeanComponent component;
     private final Class<?> type;
@@ -78,22 +80,6 @@ public class BeanInfo {
     private boolean publicConstructors;
     private boolean publicNoArgConstructors;
 
-    static {
-        // exclude all java.lang.Object methods as we dont want to invoke them
-        EXCLUDED_METHODS.addAll(Arrays.asList(Object.class.getDeclaredMethods()));
-        // exclude all java.lang.reflect.Proxy methods as we dont want to invoke them
-        EXCLUDED_METHODS.addAll(Arrays.asList(Proxy.class.getDeclaredMethods()));
-        // Remove private methods
-        EXCLUDED_METHODS.removeIf(m -> Modifier.isPrivate(m.getModifiers()));
-        try {
-            // but keep toString as this method is okay
-            EXCLUDED_METHODS.remove(Object.class.getDeclaredMethod("toString"));
-            EXCLUDED_METHODS.remove(Proxy.class.getDeclaredMethod("toString"));
-        } catch (Throwable e) {
-            // ignore
-        }
-    }
-
     public BeanInfo(CamelContext camelContext, Class<?> type) {
         this(camelContext, type, createParameterMappingStrategy(camelContext));
     }
@@ -886,10 +872,10 @@ public class BeanInfo {
      * @return true if valid, false to skip the method
      */
     protected boolean isValidMethod(Class<?> clazz, Method method) {
-        // must not be in the excluded list
-        for (Method excluded : EXCLUDED_METHODS) {
-            if (org.apache.camel.util.ObjectHelper.isOverridingMethod(excluded, method)) {
-                // the method is overriding an excluded method so its not valid
+        // method name must not be in the excluded list
+        String name = method.getName();
+        for (String s : EXCLUDED_METHOD_NAMES) {
+            if (name.equals(s)) {
                 return false;
             }
         }