You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by he...@apache.org on 2018/12/17 15:11:42 UTC
[commons-jexl] 02/02: JEXL-281: refined logic in
MethodKey.isVarArgs avoiding costly class hierarchy walk
This is an automated email from the ASF dual-hosted git repository.
henrib pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-jexl.git
commit 51a58ed28ce0a530c7854aa863849e47de294356
Author: henrib <he...@apache.org>
AuthorDate: Mon Dec 17 16:10:55 2018 +0100
JEXL-281: refined logic in MethodKey.isVarArgs avoiding costly class hierarchy walk
---
.../commons/jexl3/internal/introspection/MethodExecutor.java | 10 ++++------
.../apache/commons/jexl3/internal/introspection/MethodKey.java | 2 +-
2 files changed, 5 insertions(+), 7 deletions(-)
diff --git a/src/main/java/org/apache/commons/jexl3/internal/introspection/MethodExecutor.java b/src/main/java/org/apache/commons/jexl3/internal/introspection/MethodExecutor.java
index 61a45e7..17a66e1 100644
--- a/src/main/java/org/apache/commons/jexl3/internal/introspection/MethodExecutor.java
+++ b/src/main/java/org/apache/commons/jexl3/internal/introspection/MethodExecutor.java
@@ -70,13 +70,11 @@ public final class MethodExecutor extends AbstractExecutor.Method {
super(c, m, k);
int vastart = -1;
Class<?> vaclass = null;
- if (method != null) {
- Class<?>[] formal = method.getParameterTypes();
+ if (MethodKey.isVarArgs(method)) {
// if the last parameter is an array, the method is considered as vararg
- if (formal != null && MethodKey.isVarArgs(method)) {
- vastart = formal.length - 1;
- vaclass = formal[vastart].getComponentType();
- }
+ Class<?>[] formal = method.getParameterTypes();
+ vastart = formal.length - 1;
+ vaclass = formal[vastart].getComponentType();
}
vaStart = vastart;
vaClass = vaclass;
diff --git a/src/main/java/org/apache/commons/jexl3/internal/introspection/MethodKey.java b/src/main/java/org/apache/commons/jexl3/internal/introspection/MethodKey.java
index 229534d..1977d14 100644
--- a/src/main/java/org/apache/commons/jexl3/internal/introspection/MethodKey.java
+++ b/src/main/java/org/apache/commons/jexl3/internal/introspection/MethodKey.java
@@ -201,7 +201,7 @@ public final class MethodKey {
}
// before climbing up the hierarchy, verify that the last parameter is an array
final Class<?>[] ptypes = method.getParameterTypes();
- if (ptypes.length > 0 && ptypes[ptypes.length - 1].getComponentType() == null) {
+ if (ptypes.length == 0 || ptypes[ptypes.length - 1].getComponentType() == null) {
return false;
}
final String mname = method.getName();