This is an automated email from the ASF dual-hosted git repository.

rmaucher pushed a commit to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git

commit 51f148d2d94aaee3ee271ed47393bb4ef527c074
Author: opencode <[email protected]>
AuthorDate: Tue Oct 20 11:41:13 2026 +0200

    Ignore the resource description in the Bean resource factory
    
    BeanFactory maps each address of the resource reference to a property of
    the bean, skipping only the attributes which describe the definition of
    the resource rather than the resource itself. The description is such an
    attribute: ResourceRef stores it as an address whenever a resource is
    defined with a description and NamingContextListener always passes it on.
    
    Almost no bean has a property named description, so the effect was that a
    bean resource defined with a description failed every lookup with the
    message that no set method was found for the property [description]. For
    the rare bean which does have such a property, the description of the
    resource definition was silently set on the bean, which was equally wrong
    since the description describes the resource, not the object which
    implements it.
    
    The description is now skipped in the same way as the scope and the
    authentication type. This matches the default factory of the data source,
    which only ever reads the property names it knows of and therefore never
    passed the description to the object it created.
    
    Add a regression test.
---
 java/org/apache/naming/factory/BeanFactory.java    |  3 ++-
 .../org/apache/naming/factory/TestBeanFactory.java | 27 ++++++++++++++++++++++
 2 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/java/org/apache/naming/factory/BeanFactory.java 
b/java/org/apache/naming/factory/BeanFactory.java
index fde7c5e4a5..0d5a785cec 100644
--- a/java/org/apache/naming/factory/BeanFactory.java
+++ b/java/org/apache/naming/factory/BeanFactory.java
@@ -122,7 +122,8 @@ public class BeanFactory implements ObjectFactory {
                     String propName = ra.getType();
 
                     if (propName.equals(Constants.FACTORY) || 
propName.equals("scope") || propName.equals("auth") ||
-                            propName.equals("forceString") || 
propName.equals("singleton")) {
+                            propName.equals("description") || 
propName.equals("forceString") ||
+                            propName.equals("singleton")) {
                         continue;
                     }
 
diff --git a/test/org/apache/naming/factory/TestBeanFactory.java 
b/test/org/apache/naming/factory/TestBeanFactory.java
index ec85ff6136..79912c7d0c 100644
--- a/test/org/apache/naming/factory/TestBeanFactory.java
+++ b/test/org/apache/naming/factory/TestBeanFactory.java
@@ -64,4 +64,31 @@ public class TestBeanFactory {
         Assert.assertNotNull(result.getServer());
         Assert.assertEquals(IP_ADDRESS, result.getServer().getHostAddress());
     }
+
+
+    /*
+     * The description of a resource is a property of the resource definition
+     * and not a property of the bean, so the factory has to ignore it.
+     */
+    @Test
+    public void testDescriptionIsNotPassedToTheBean() throws Exception {
+
+        // Create the resource definition with a description
+        ResourceRef resourceRef = new ResourceRef(TesterBean.class.getName(), 
"The tester bean", null, null, false);
+        resourceRef.add(new StringRefAddr("server", IP_ADDRESS));
+
+        // Create the factory
+        BeanFactory factory = new BeanFactory();
+
+        // Use the factory to create the resource from the definition
+        Object obj = factory.getObjectInstance(resourceRef, null, null, null);
+
+        // Check the correct type was created
+        Assert.assertNotNull(obj);
+        Assert.assertEquals(obj.getClass(), TesterBean.class);
+        // Check the description was ignored and only the server field was set
+        TesterBean result = (TesterBean) obj;
+        Assert.assertNotNull(result.getServer());
+        Assert.assertEquals(IP_ADDRESS, result.getServer().getHostAddress());
+    }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to