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 380fb11 Add default method support to BeanELResolver
380fb11 is described below
commit 380fb1144b9ba68494b1c42397141ebe21af8a8d
Author: Mark Thomas <[email protected]>
AuthorDate: Tue Sep 7 17:46:02 2021 +0100
Add default method support to BeanELResolver
---
java/jakarta/el/BeanELResolver.java | 12 +++++++-----
test/jakarta/el/TestBeanELResolver.java | 25 ++++++++++++++++++++++++-
webapps/docs/changelog.xml | 5 +++++
3 files changed, 36 insertions(+), 6 deletions(-)
diff --git a/java/jakarta/el/BeanELResolver.java
b/java/jakarta/el/BeanELResolver.java
index 07c7f24..2b6f455 100644
--- a/java/jakarta/el/BeanELResolver.java
+++ b/java/jakarta/el/BeanELResolver.java
@@ -215,11 +215,13 @@ public class BeanELResolver extends ELResolver {
for (PropertyDescriptor pd: pds) {
this.properties.put(pd.getName(), new BeanProperty(type,
pd));
}
- if (System.getSecurityManager() != null) {
- // When running with SecurityManager, some classes may be
- // not accessible, but have accessible interfaces.
- populateFromInterfaces(type);
- }
+ /**
+ * Populating from any interfaces solves two distinct problems:
+ * 1. When running under a security manager, classes may be
+ * unaccessible but have accessible interfaces.
+ * 2. It causes default methods to be included.
+ */
+ populateFromInterfaces(type);
} catch (IntrospectionException ie) {
throw new ELException(ie);
}
diff --git a/test/jakarta/el/TestBeanELResolver.java
b/test/jakarta/el/TestBeanELResolver.java
index 88fd6ff..6847aca 100644
--- a/test/jakarta/el/TestBeanELResolver.java
+++ b/test/jakarta/el/TestBeanELResolver.java
@@ -939,7 +939,22 @@ public class TestBeanELResolver {
Assert.assertEquals(BEAN_NAME, result);
}
- private static class Bean {
+ /**
+ * Tests that a valid property implemented by a default method is resolved.
+ */
+ @Test
+ public void testGetDefaultValue() {
+ BeanELResolver resolver = new BeanELResolver();
+ ELContext context = new
StandardELContext(ELManager.getExpressionFactory());
+
+ Object result = resolver.getValue(context, new Bean(),
PROPERTY02_NAME);
+
+ Assert.assertEquals("Default", result);
+ Assert.assertTrue(context.isPropertyResolved());
+ }
+
+
+ private static class Bean implements MyInterface {
@SuppressWarnings("unused")
public void setValueA(String valueA) {
@@ -947,6 +962,14 @@ public class TestBeanELResolver {
}
}
+
+ public interface MyInterface {
+ default String getValueB() {
+ return "Default";
+ }
+ }
+
+
private void doNegativeTest(Object base, Object trigger, MethodUnderTest
method,
boolean checkResult) {
BeanELResolver resolver = new BeanELResolver();
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 6bb894b..be86080 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -111,6 +111,11 @@
Deprecate <code>ELResolver.getFeatureDescriptors</code> to align Tomcat
with recent updates in the Jakarta EL specification project. (markt)
</scode>
+ <add>
+ Add support for default methods to <code>BeanRELResolver</code> to
align
+ Tomcat with recent updates in the Jakarta EL specification project.
+ (markt)
+ </add>
</changelog>
</subsection>
</section>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]