This is an automated email from the ASF dual-hosted git repository.
benweidig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tapestry-5.git
The following commit(s) were added to refs/heads/master by this push:
new 0dbc5bd3d TAP5-2826: allow null value for render variables
0dbc5bd3d is described below
commit 0dbc5bd3da5e62d54667b534542a5c36b158de1e
Author: Ben Weidig <[email protected]>
AuthorDate: Mon Apr 20 08:27:53 2026 +0200
TAP5-2826: allow null value for render variables
---
.../org/apache/tapestry5/ComponentResources.java | 2 +-
.../structure/InternalComponentResourcesImpl.java | 7 ++----
tapestry-core/src/test/app1/DelegateInline.tml | 4 ++++
.../integration/app1/GeneralComponentTests.java | 6 ++++-
.../integration/app1/pages/DelegateInline.java | 7 +++++-
.../InternalComponentResourcesImplTest.java | 27 +++++++++++++++++++++-
6 files changed, 44 insertions(+), 9 deletions(-)
diff --git
a/tapestry-core/src/main/java/org/apache/tapestry5/ComponentResources.java
b/tapestry-core/src/main/java/org/apache/tapestry5/ComponentResources.java
index 306fc8635..f991acbc7 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/ComponentResources.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/ComponentResources.java
@@ -175,7 +175,7 @@ public interface ComponentResources extends
ComponentResourcesCommon
* @param name
* of value to store
* @param value
- * value to store (may not be null)
+ * value to store
* @throws IllegalStateException
* if the component is not currently rendering
*/
diff --git
a/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/InternalComponentResourcesImpl.java
b/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/InternalComponentResourcesImpl.java
index 08f72aa25..eb80ee40c 100644
---
a/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/InternalComponentResourcesImpl.java
+++
b/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/InternalComponentResourcesImpl.java
@@ -551,21 +551,18 @@ public class InternalComponentResourcesImpl extends
LockSupport implements Inter
{
Map<String, Object> variablesMap = getRenderVariables(false);
- Object result = InternalUtils.get(variablesMap, name);
-
- if (result == null)
+ if (variablesMap == null || !variablesMap.containsKey(name))
{
throw new
IllegalArgumentException(StructureMessages.missingRenderVariable(getCompleteId(),
name,
variablesMap == null ? null : variablesMap.keySet()));
}
- return result;
+ return InternalUtils.get(variablesMap, name);
}
public void storeRenderVariable(String name, Object value)
{
assert InternalUtils.isNonBlank(name);
- assert value != null;
Map<String, Object> renderVariables = getRenderVariables(true);
diff --git a/tapestry-core/src/test/app1/DelegateInline.tml
b/tapestry-core/src/test/app1/DelegateInline.tml
index c7871a9cf..00b95fa5f 100644
--- a/tapestry-core/src/test/app1/DelegateInline.tml
+++ b/tapestry-core/src/test/app1/DelegateInline.tml
@@ -4,8 +4,12 @@
<t:delegate to="block:block1" />
<t:delegate to="block:block2" firstName="Steve" lastName="Rogers" />
<t:delegate to="block:block2" firstName="Bruce" lastName="Banner" />
+ <t:delegate to="block:block3" renderVar="prop:nullRenderVar" />
<t:block id="block1"><span id="block1">block 1</span></t:block>
<t:block id="block2"><p class="superhero">${var:firstName}
${var:lastName}</p></t:block>
+
+ <t:block id="block3"><p id="block3"><t:if test="var:renderVar"
then="literal:notNull" else="literal:isNull" /></p></t:block>
+
</t:border>
diff --git
a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/GeneralComponentTests.java
b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/GeneralComponentTests.java
index 4fc65dbba..b694e1b26 100644
---
a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/GeneralComponentTests.java
+++
b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/GeneralComponentTests.java
@@ -94,10 +94,14 @@ public class GeneralComponentTests extends App1TestCase
// multiple renders w/ multiple parameters
assertText("xpath=(//p[@class='superhero'])[1]", "Steve Rogers");
assertText("xpath=(//p[@class='superhero'])[2]", "Bruce Banner");
+
+ assertText("block3", "isNull");
+
}
/** TAP5-742 */
- @Test public void component_tracing_comments() throws Exception {
+ @Test public void component_tracing_comments() throws Exception
+ {
String contents = IOUtils.toString(new URL(getBaseURL()).openStream());
// off by default
diff --git
a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/DelegateInline.java
b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/DelegateInline.java
index e0692cb16..2146499d4 100644
---
a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/DelegateInline.java
+++
b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/DelegateInline.java
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007, 2008, 2009, 2010 The Apache Software Foundation
+// Copyright 2006-2010, 2026 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -16,4 +16,9 @@ package org.apache.tapestry5.integration.app1.pages;
public class DelegateInline {
+ // TAP5-2826
+ public String getNullRenderVar()
+ {
+ return null;
+ }
}
diff --git
a/tapestry-core/src/test/java/org/apache/tapestry5/internal/structure/InternalComponentResourcesImplTest.java
b/tapestry-core/src/test/java/org/apache/tapestry5/internal/structure/InternalComponentResourcesImplTest.java
index 33422c496..8de261d0f 100644
---
a/tapestry-core/src/test/java/org/apache/tapestry5/internal/structure/InternalComponentResourcesImplTest.java
+++
b/tapestry-core/src/test/java/org/apache/tapestry5/internal/structure/InternalComponentResourcesImplTest.java
@@ -1,4 +1,4 @@
-// Copyright 2006-2014 The Apache Software Foundation
+// Copyright 2006-2014, 2026 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -299,4 +299,29 @@ public class InternalComponentResourcesImplTest extends
InternalBaseTestCase
verify();
}
+
+ // TAP5-2826
+ @Test
+ public void get_set_render_variable_null()
+ {
+ Component component = mockComponent();
+ Instantiator ins = mockInstantiator(component);
+ ComponentModel model = mockComponentModel();
+
+ train_getModel(ins, model);
+
+ replay();
+
+ ComponentResources resources = new
InternalComponentResourcesImpl(null, null, null, elementResources, "id",
+ null, ins, false);
+
+ resources.storeRenderVariable("myRenderVar", null);
+
+ Object result = resources.getRenderVariable("myRenderVar");
+
+ assertNull(result);
+
+ verify();
+ }
+
}