You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2019/10/04 20:24:01 UTC
[tomcat] branch master updated: Fix NPEs when looking for static
methods
This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/master by this push:
new ae08feb Fix NPEs when looking for static methods
ae08feb is described below
commit ae08febd4d053d38df876b039d4b632a79465510
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Fri Oct 4 21:23:42 2019 +0100
Fix NPEs when looking for static methods
---
java/javax/el/StaticFieldELResolver.java | 10 ++++++----
java/javax/el/Util.java | 6 +++++-
java/org/apache/el/util/ReflectionUtil.java | 6 +++++-
3 files changed, 16 insertions(+), 6 deletions(-)
diff --git a/java/javax/el/StaticFieldELResolver.java b/java/javax/el/StaticFieldELResolver.java
index 5b3afaf..d6a9027 100644
--- a/java/javax/el/StaticFieldELResolver.java
+++ b/java/javax/el/StaticFieldELResolver.java
@@ -113,11 +113,13 @@ public class StaticFieldELResolver extends ELResolver {
return result;
} else {
- Method match =
- Util.findMethod(clazz, base, methodName, paramTypes, params);
+ // Static method so base should be null
+ Method match = Util.findMethod(clazz, null, methodName, paramTypes, params);
- int modifiers = match.getModifiers();
- if (!Modifier.isStatic(modifiers)) {
+ // Note: On Java 9 and above, the isStatic check becomes
+ // unnecessary because the canAccess() call in Util.findMethod()
+ // effectively performs the same check
+ if (match == null || !Modifier.isStatic(match.getModifiers())) {
throw new MethodNotFoundException(Util.message(context,
"staticFieldELResolver.methodNotFound", methodName,
clazz.getName()));
diff --git a/java/javax/el/Util.java b/java/javax/el/Util.java
index e64e9a3..2e06837 100644
--- a/java/javax/el/Util.java
+++ b/java/javax/el/Util.java
@@ -541,7 +541,11 @@ class Util {
*/
static Method getMethod(Class<?> type, Object base, Method m) {
JreCompat jreCompat = JreCompat.getInstance();
- if (m == null || (Modifier.isPublic(type.getModifiers()) && jreCompat.canAcccess(base, m))) {
+ // If base is null, method MUST be static
+ // If base is non-null, method may be static or non-static
+ if (m == null ||
+ (Modifier.isPublic(type.getModifiers()) &&
+ (jreCompat.canAcccess(base, m) || base != null && jreCompat.canAcccess(null, m)))) {
return m;
}
Class<?>[] inf = type.getInterfaces();
diff --git a/java/org/apache/el/util/ReflectionUtil.java b/java/org/apache/el/util/ReflectionUtil.java
index 4856cbb..c9f1f2e 100644
--- a/java/org/apache/el/util/ReflectionUtil.java
+++ b/java/org/apache/el/util/ReflectionUtil.java
@@ -424,7 +424,11 @@ public class ReflectionUtil {
*/
private static Method getMethod(Class<?> type, Object base, Method m) {
JreCompat jreCompat = JreCompat.getInstance();
- if (m == null || (Modifier.isPublic(type.getModifiers()) && jreCompat.canAcccess(base, m))) {
+ // If base is null, method MUST be static
+ // If base is non-null, method may be static or non-static
+ if (m == null ||
+ (Modifier.isPublic(type.getModifiers()) &&
+ (jreCompat.canAcccess(base, m) || base != null && jreCompat.canAcccess(null, m)))) {
return m;
}
Class<?>[] inf = type.getInterfaces();
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org