You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by bo...@apache.org on 2023/08/01 13:02:25 UTC
[myfaces-tobago] branch tobago-5.x updated: fix(core): Avoid NPE in HtmlRendererUtils#writeDataAttributes issue: TOBAGO-2244
This is an automated email from the ASF dual-hosted git repository.
bommel pushed a commit to branch tobago-5.x
in repository https://gitbox.apache.org/repos/asf/myfaces-tobago.git
The following commit(s) were added to refs/heads/tobago-5.x by this push:
new fb3cbb2a4a fix(core): Avoid NPE in HtmlRendererUtils#writeDataAttributes issue: TOBAGO-2244
fb3cbb2a4a is described below
commit fb3cbb2a4aafc7a299b544c11a9d62c1abc4a317
Author: Bernd Bohmann <bo...@apache.org>
AuthorDate: Mon Jul 31 21:20:57 2023 +0200
fix(core): Avoid NPE in HtmlRendererUtils#writeDataAttributes
issue: TOBAGO-2244
(cherry picked from commit b6c295e88d6b0523ffdcc01ac017d0b59e0c419b)
---
.../tobago/internal/util/HtmlRendererUtils.java | 22 +++++++++++++++++-----
1 file changed, 17 insertions(+), 5 deletions(-)
diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/util/HtmlRendererUtils.java b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/util/HtmlRendererUtils.java
index 73cc190a50..4919f43ed5 100644
--- a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/util/HtmlRendererUtils.java
+++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/util/HtmlRendererUtils.java
@@ -162,12 +162,24 @@ public final class HtmlRendererUtils {
for (final Map.Entry<Object, Object> entry : dataAttributes.entrySet()) {
final Object mapKey = entry.getKey();
- final String name = mapKey instanceof ValueExpression
- ? ((ValueExpression) mapKey).getValue(elContext).toString() : mapKey.toString();
+ final String name;
+ if (mapKey instanceof ValueExpression) {
+ Object expressionValue = ((ValueExpression) mapKey).getValue(elContext);
+ name = expressionValue != null ? expressionValue.toString() : null;
+ } else {
+ name = mapKey.toString();
+ }
final Object mapValue = entry.getValue();
- final String value = mapValue instanceof ValueExpression
- ? ((ValueExpression) mapValue).getValue(elContext).toString() : mapValue.toString();
- writer.writeAttribute(DataAttributes.dynamic(name), value, true);
+ final String value;
+ if (mapValue instanceof ValueExpression) {
+ Object expressionValue = ((ValueExpression) mapValue).getValue(elContext);
+ value = expressionValue !=null ? expressionValue.toString() : null;
+ } else {
+ value = mapValue.toString();
+ }
+ if (name != null && value != null) {
+ writer.writeAttribute(DataAttributes.dynamic(name), value, true);
+ }
}
}
}