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/03 18:12:50 UTC
[tomcat] branch 7.0.x updated: Prep fix for
https://bz.apache.org/bugzilla/show_bug.cgi?id=63781
This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch 7.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/7.0.x by this push:
new f187e83 Prep fix for https://bz.apache.org/bugzilla/show_bug.cgi?id=63781
f187e83 is described below
commit f187e83c6f007e2f5957697d3ae74ec2263db172
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Thu Oct 3 19:02:00 2019 +0100
Prep fix for https://bz.apache.org/bugzilla/show_bug.cgi?id=63781
Add canAccess to JreCompat and create cut-down version of JreCompat for
EL API implementation.
---
java/javax/el/Jre9Compat.java | 56 ++++++++++++++++++++
java/javax/el/JreCompat.java | 60 ++++++++++++++++++++++
java/org/apache/tomcat/util/compat/Jre9Compat.java | 21 +++++++-
java/org/apache/tomcat/util/compat/JreCompat.java | 20 ++++++++
4 files changed, 156 insertions(+), 1 deletion(-)
diff --git a/java/javax/el/Jre9Compat.java b/java/javax/el/Jre9Compat.java
new file mode 100644
index 0000000..55110cd
--- /dev/null
+++ b/java/javax/el/Jre9Compat.java
@@ -0,0 +1,56 @@
+/*
+ * 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 javax.el;
+
+import java.lang.reflect.AccessibleObject;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+class Jre9Compat extends JreCompat {
+
+ private static final Method canAccessMethod;
+
+
+ static {
+ Method m1 = null;
+ try {
+ m1 = AccessibleObject.class.getMethod("canAccess", new Class<?>[] { Object.class });
+ } catch (NoSuchMethodException e) {
+ // Expected for Java 8
+ }
+ canAccessMethod = m1;
+ }
+
+
+ public static boolean isSupported() {
+ return canAccessMethod != null;
+ }
+
+
+ @Override
+ public boolean canAcccess(Class<?> type, Object base, AccessibleObject accessibleObject) {
+ try {
+ return ((Boolean) canAccessMethod.invoke(accessibleObject, base)).booleanValue();
+ } catch (IllegalArgumentException e) {
+ return false;
+ } catch (IllegalAccessException e) {
+ return false;
+ } catch (InvocationTargetException e) {
+ return false;
+ }
+ }
+}
diff --git a/java/javax/el/JreCompat.java b/java/javax/el/JreCompat.java
new file mode 100644
index 0000000..b01d94e
--- /dev/null
+++ b/java/javax/el/JreCompat.java
@@ -0,0 +1,60 @@
+/*
+ * 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 javax.el;
+
+import java.lang.reflect.AccessibleObject;
+import java.lang.reflect.Modifier;
+
+/*
+ * This is cut down version of org.apache.tomcat.util.JreCompat that provides
+ * only the methods required by the EL implementation.
+ */
+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 of the given type accessible on the provided
+ * instance of that type.
+ *
+ * @param type The type the accessible object belongs to
+ * @param base The specific instance of the type to be tested. Unused prior
+ * to Java 9.
+ * @param accessibleObject The method/field/constructor to be tested.
+ * Unused prior to Java 9.
+ *
+ * @return {code true} if the AccessibleObject can be accessed otherwise
+ * {code false}
+ */
+ public boolean canAcccess(Class<?> type, Object base, AccessibleObject accessibleObject) {
+ return Modifier.isPublic(type.getModifiers());
+ }
+}
diff --git a/java/org/apache/tomcat/util/compat/Jre9Compat.java b/java/org/apache/tomcat/util/compat/Jre9Compat.java
index 68be1db..debf9c2 100644
--- a/java/org/apache/tomcat/util/compat/Jre9Compat.java
+++ b/java/org/apache/tomcat/util/compat/Jre9Compat.java
@@ -18,6 +18,7 @@ package org.apache.tomcat.util.compat;
import java.io.File;
import java.io.IOException;
+import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
@@ -50,9 +51,9 @@ class Jre9Compat extends Jre8Compat {
private static final Method getMethod;
private static final Constructor<JarFile> jarFileConstructor;
private static final Method isMultiReleaseMethod;
-
private static final Object RUNTIME_VERSION;
private static final int RUNTIME_MAJOR_VERSION;
+ private static final Method canAccessMethod;
static {
Class<?> c1 = null;
@@ -68,6 +69,7 @@ class Jre9Compat extends Jre8Compat {
Method m13 = null;
Object o14 = null;
Object o15 = null;
+ Method m16 = null;
try {
// Order is important for the error handling below.
@@ -95,6 +97,7 @@ class Jre9Compat extends Jre8Compat {
m13 = JarFile.class.getMethod("isMultiRelease");
o14 = runtimeVersionMethod.invoke(null);
o15 = majorMethod.invoke(o14);
+ m16 = AccessibleObject.class.getMethod("canAccess", new Class<?>[] { Object.class });
} catch (SecurityException e) {
// Should never happen
@@ -140,6 +143,8 @@ class Jre9Compat extends Jre8Compat {
// Must be Java 8
RUNTIME_MAJOR_VERSION = 8;
}
+
+ canAccessMethod = m16;
}
@@ -237,4 +242,18 @@ class Jre9Compat extends Jre8Compat {
public int jarFileRuntimeMajorVersion() {
return RUNTIME_MAJOR_VERSION;
}
+
+
+ @Override
+ public boolean canAcccess(Class<?> type, Object base, AccessibleObject accessibleObject) {
+ try {
+ return ((Boolean) canAccessMethod.invoke(accessibleObject, base)).booleanValue();
+ } catch (IllegalArgumentException e) {
+ return false;
+ } catch (IllegalAccessException e) {
+ return false;
+ } catch (InvocationTargetException e) {
+ return false;
+ }
+ }
}
diff --git a/java/org/apache/tomcat/util/compat/JreCompat.java b/java/org/apache/tomcat/util/compat/JreCompat.java
index 80825e5..7e0c92a 100644
--- a/java/org/apache/tomcat/util/compat/JreCompat.java
+++ b/java/org/apache/tomcat/util/compat/JreCompat.java
@@ -19,7 +19,9 @@ package org.apache.tomcat.util.compat;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
+import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
import java.net.URL;
import java.net.URLConnection;
import java.sql.CallableStatement;
@@ -345,4 +347,22 @@ public class JreCompat {
}
return false;
}
+
+
+ /**
+ * Is the accessibleObject of the given type accessible on the provided
+ * instance of that type.
+ *
+ * @param type The type the accessible object belongs to
+ * @param base The specific instance of the type to be tested. Unused prior
+ * to Java 9.
+ * @param accessibleObject The method/field/constructor to be tested.
+ * Unused prior to Java 9.
+ *
+ * @return {code true} if the AccessibleObject can be accessed otherwise
+ * {code false}
+ */
+ public boolean canAcccess(Class<?> type, Object base, AccessibleObject accessibleObject) {
+ return Modifier.isPublic(type.getModifiers());
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org