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 35bfd9fdeb00cdb5cb4ce5712671b1a395d319f9
Author: opencode <[email protected]>
AuthorDate: Mon Oct 19 10:29:24 2026 +0200

    Avoid NullPointerException writing a null bean property value
    
    GraalBeanELResolver.setValue() derived the value class from the value
    itself in order to select a setter whose parameter type the value could
    be assigned to. A null value has no class, so writing null to any bean
    property raised a NullPointerException under GraalVM native image.
    
    Compute the value class defensively and pass null to getWriteMethod(),
    which already treats a null value class as matching any setter, so a
    reference-typed setter now receives the null value. Extend the existing
    Graal resolver test with the null value case and a type mismatch case
    that asserts the property is left unresolved.
    
    Found by code review.
---
 java/org/apache/jasper/el/JasperELResolver.java     |  5 ++++-
 test/org/apache/jasper/el/TestJasperELResolver.java | 15 +++++++++++++++
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/java/org/apache/jasper/el/JasperELResolver.java 
b/java/org/apache/jasper/el/JasperELResolver.java
index e30dcfb076..ac003b893c 100644
--- a/java/org/apache/jasper/el/JasperELResolver.java
+++ b/java/org/apache/jasper/el/JasperELResolver.java
@@ -225,7 +225,10 @@ public class JasperELResolver extends CompositeELResolver {
             if (base == null || property == null) {
                 return;
             }
-            Method method = getWriteMethod(base.getClass(), 
property.toString(), value.getClass());
+            // A null value has no class to check the setter against. Pass null
+            // and let getWriteMethod() select a reference-typed setter
+            Class<?> valueClass = value == null ? null : value.getClass();
+            Method method = getWriteMethod(base.getClass(), 
property.toString(), valueClass);
             if (method != null) {
                 context.setPropertyResolved(base, property);
                 try {
diff --git a/test/org/apache/jasper/el/TestJasperELResolver.java 
b/test/org/apache/jasper/el/TestJasperELResolver.java
index d368e0773d..14c6c37edd 100644
--- a/test/org/apache/jasper/el/TestJasperELResolver.java
+++ b/test/org/apache/jasper/el/TestJasperELResolver.java
@@ -94,6 +94,21 @@ public class TestJasperELResolver {
         TestBean bean = new TestBean();
         resolver.setValue(context, bean, "bla", "a string value");
         Assert.assertEquals("a string value", bean.getLastBla());
+
+        // A null value has no class to check the setter against. It must reach
+        // a setter whose parameter can hold null. Before the fix, deriving the
+        // value class from the null value caused a NullPointerException here.
+        context.setPropertyResolved(false);
+        resolver.setValue(context, bean, "bla", null);
+        Assert.assertNull("A null value should be written to a reference-typed 
setter", bean.getLastBla());
+        Assert.assertTrue("A null value should resolve the property", 
context.isPropertyResolved());
+
+        // A value whose type the setter parameter cannot hold must be left
+        // unresolved so that another resolver in the chain can handle it
+        context.setPropertyResolved(false);
+        resolver.setValue(context, bean, "foo", Integer.valueOf(7));
+        Assert.assertFalse("A mismatched value must leave the property 
unresolved",
+                context.isPropertyResolved());
     }
 
     public static class TestBean {


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

Reply via email to