This is an automated email from the ASF dual-hosted git repository. rmaucher pushed a commit to branch 10.1.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
commit 5162412292d5d36b52cecfd7e1279f326dcdabc2 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 e7f33bb8e3..8fb27a8d77 100644 --- a/java/org/apache/jasper/el/JasperELResolver.java +++ b/java/org/apache/jasper/el/JasperELResolver.java @@ -231,7 +231,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 465e6faaa3..a6f202c36c 100644 --- a/test/org/apache/jasper/el/TestJasperELResolver.java +++ b/test/org/apache/jasper/el/TestJasperELResolver.java @@ -96,6 +96,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]
