This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/main by this push: new 335bed0 Remove JreCompat from EL API as it is no longer required. 335bed0 is described below commit 335bed06af17759de0fcb46235f257bbea301299 Author: Mark Thomas <ma...@apache.org> AuthorDate: Wed Jul 28 12:08:10 2021 +0100 Remove JreCompat from EL API as it is no longer required. --- java/jakarta/el/ELProcessor.java | 6 +-- java/jakarta/el/ImportHandler.java | 14 +++-- java/jakarta/el/Jre9Compat.java | 83 ------------------------------ java/jakarta/el/JreCompat.java | 73 -------------------------- java/jakarta/el/StaticFieldELResolver.java | 6 +-- java/jakarta/el/Util.java | 6 +-- 6 files changed, 16 insertions(+), 172 deletions(-) diff --git a/java/jakarta/el/ELProcessor.java b/java/jakarta/el/ELProcessor.java index aea604a..61d8a2a 100644 --- a/java/jakarta/el/ELProcessor.java +++ b/java/jakarta/el/ELProcessor.java @@ -113,13 +113,12 @@ public class ELProcessor { // Only returns public methods. Java 9+ access is checked below. Method methods[] = clazz.getMethods(); - JreCompat jreCompat = JreCompat.getInstance(); for (Method method : methods) { if (!Modifier.isStatic(method.getModifiers())) { continue; } - if (!jreCompat.canAccess(null, method)) { + if (!method.canAccess(null)) { continue; } if (method.getName().equals(sig.getName())) { @@ -193,8 +192,7 @@ public class ELProcessor { int modifiers = method.getModifiers(); // Check for static, public method and module access for Java 9+ - JreCompat jreCompat = JreCompat.getInstance(); - if (!Modifier.isStatic(modifiers) || !jreCompat.canAccess(null, method)) { + if (!Modifier.isStatic(modifiers) || !method.canAccess(null)) { throw new NoSuchMethodException(Util.message(context, "elProcessor.defineFunctionInvalidMethod", method.getName(), method.getDeclaringClass().getName())); diff --git a/java/jakarta/el/ImportHandler.java b/java/jakarta/el/ImportHandler.java index 018f53d..899da78 100644 --- a/java/jakarta/el/ImportHandler.java +++ b/java/jakarta/el/ImportHandler.java @@ -479,12 +479,11 @@ public class ImportHandler { return null; } - // Class must be public, non-abstract, not an interface and (for - // Java 9+) in an exported package - JreCompat jreCompat = JreCompat.getInstance(); + // Class must be public, non-abstract, not an interface and in an + // exported package int modifiers = clazz.getModifiers(); if (!Modifier.isPublic(modifiers) || Modifier.isAbstract(modifiers) || - Modifier.isInterface(modifiers) || !jreCompat.isExported(clazz)) { + Modifier.isInterface(modifiers) || !isExported(clazz)) { if (throwException) { throw new ELException(Util.message( null, "importHandler.invalidClass", name)); @@ -497,6 +496,13 @@ public class ImportHandler { } + public static boolean isExported(Class<?> type) { + String packageName = type.getPackage().getName(); + Module module = type.getModule(); + return module.isExported(packageName); + } + + /* * Marker class used because null values are not permitted in a * ConcurrentHashMap. diff --git a/java/jakarta/el/Jre9Compat.java b/java/jakarta/el/Jre9Compat.java deleted file mode 100644 index a4451ff..0000000 --- a/java/jakarta/el/Jre9Compat.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package jakarta.el; - -import java.lang.reflect.AccessibleObject; -import java.lang.reflect.Method; - -/* - * This is a cut down version of org.apache.tomcat.util.Jre9Compat that provides - * only the methods required by the EL implementation. - * - * This class is duplicated in org.apache.el.util - * When making changes keep the two in sync. - */ -class Jre9Compat extends JreCompat { - - private static final Method canAccessMethod; - private static final Method getModuleMethod; - private static final Method isExportedMethod; - - static { - Method m1 = null; - Method m2 = null; - Method m3 = null; - - try { - m1 = AccessibleObject.class.getMethod("canAccess", Object.class); - m2 = Class.class.getMethod("getModule"); - Class<?> moduleClass = Class.forName("java.lang.Module"); - m3 = moduleClass.getMethod("isExported", String.class); - } catch (NoSuchMethodException e) { - // Expected for Java 8 - } catch (ClassNotFoundException e) { - // Can't log this so... - throw new RuntimeException(e); - } - - canAccessMethod = m1; - getModuleMethod = m2; - isExportedMethod = m3; - } - - - public static boolean isSupported() { - return canAccessMethod != null; - } - - - @Override - public boolean canAccess(Object base, AccessibleObject accessibleObject) { - try { - return ((Boolean) canAccessMethod.invoke(accessibleObject, base)).booleanValue(); - } catch (ReflectiveOperationException | IllegalArgumentException e) { - return false; - } - } - - - @Override - public boolean isExported(Class<?> type) { - try { - String packageName = type.getPackage().getName(); - Object module = getModuleMethod.invoke(type); - return ((Boolean) isExportedMethod.invoke(module, packageName)).booleanValue(); - } catch (ReflectiveOperationException e) { - return false; - } - } -} diff --git a/java/jakarta/el/JreCompat.java b/java/jakarta/el/JreCompat.java deleted file mode 100644 index 1bfb934..0000000 --- a/java/jakarta/el/JreCompat.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package jakarta.el; - -import java.lang.reflect.AccessibleObject; - -/* - * This is cut down version of org.apache.tomcat.util.JreCompat that provides - * only the methods required by the EL implementation. - * - * This class is duplicated in org.apache.el.util - * When making changes keep the two in sync. - */ -class JreCompat { - - private static final JreCompat instance; - - static { - if (Jre9Compat.isSupported()) { - instance = new Jre9Compat(); - } else { - instance = new JreCompat(); - } - } - - - public static JreCompat getInstance() { - return instance; - } - - - /** - * Is the accessibleObject accessible (as a result of appropriate module - * exports) on the provided instance? - * - * @param base The specific instance to be tested. - * @param accessibleObject The method/field/constructor to be tested. - * - * @return {code true} if the AccessibleObject can be accessed otherwise - * {code false} - */ - public boolean canAccess(Object base, AccessibleObject accessibleObject) { - // Java 8 doesn't support modules so default to true - return true; - } - - - /** - * Is the given class in an exported package? - * - * @param type The class to test - * - * @return Always {@code true} for Java 8. {@code true} if the enclosing - * package is exported for Java 9+ - */ - public boolean isExported(Class<?> type) { - return true; - } -} diff --git a/java/jakarta/el/StaticFieldELResolver.java b/java/jakarta/el/StaticFieldELResolver.java index 473c414..84cb871 100644 --- a/java/jakarta/el/StaticFieldELResolver.java +++ b/java/jakarta/el/StaticFieldELResolver.java @@ -43,10 +43,9 @@ public class StaticFieldELResolver extends ELResolver { try { Field field = clazz.getField(name); int modifiers = field.getModifiers(); - JreCompat jreCompat = JreCompat.getInstance(); if (Modifier.isStatic(modifiers) && Modifier.isPublic(modifiers) && - jreCompat.canAccess(null, field)) { + field.canAccess(null)) { return field.get(null); } } catch (IllegalArgumentException | IllegalAccessException | @@ -157,10 +156,9 @@ public class StaticFieldELResolver extends ELResolver { try { Field field = clazz.getField(name); int modifiers = field.getModifiers(); - JreCompat jreCompat = JreCompat.getInstance(); if (Modifier.isStatic(modifiers) && Modifier.isPublic(modifiers) && - jreCompat.canAccess(null, field)) { + field.canAccess(field)) { return field.getType(); } } catch (IllegalArgumentException | NoSuchFieldException | diff --git a/java/jakarta/el/Util.java b/java/jakarta/el/Util.java index 80a6ee0..3bfd267 100644 --- a/java/jakarta/el/Util.java +++ b/java/jakarta/el/Util.java @@ -543,12 +543,11 @@ class Util { * making changes keep the code in sync. */ static Method getMethod(Class<?> type, Object base, Method m) { - JreCompat jreCompat = JreCompat.getInstance(); // 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.canAccess(base, m) || base != null && jreCompat.canAccess(null, m)))) { + (m.canAccess(base) || base != null && m.canAccess(null)))) { return m; } Class<?>[] interfaces = type.getInterfaces(); @@ -603,8 +602,7 @@ class Util { Constructor<?> constructor = wrapper.unWrap(); - JreCompat jreCompat = JreCompat.getInstance(); - if (!Modifier.isPublic(clazz.getModifiers()) || !jreCompat.canAccess(null, constructor)) { + if (!Modifier.isPublic(clazz.getModifiers()) || !constructor.canAccess(null)) { throw new MethodNotFoundException(message( null, "util.method.notfound", clazz, methodName, paramString(paramTypes))); --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org