[
https://issues.apache.org/jira/browse/SLING-9314?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17184103#comment-17184103
]
Paul Bjorkstrand commented on SLING-9314:
-----------------------------------------
That works too, [~radu]. This was mainly a "quick get the details down" kind of
report, that I did not yet follow up on. The suggestion for falsey was based on
my specific situation. It might be worthwhile to add a warn/error log when
toString returns null.
As I stated in the first sentence, it is bad practice (and ostensibly breaks
the contract of {{#toString}}) but that does not stop bad code from sneaking
in. Thinking for both allowing further processing and helping with
troubleshooting something like this maybe (pseudocode):
{code}
s = o.toString();
if (s == null) {
log warn or error with as much detail as possible
s = EMPTY
}
s = s.trim()
... the rest of the logic ...
{code}
> HTL null pointer in ObjectModel.toBoolean(Object) when object.toString()
> returns null
> -------------------------------------------------------------------------------------
>
> Key: SLING-9314
> URL: https://issues.apache.org/jira/browse/SLING-9314
> Project: Sling
> Issue Type: Bug
> Components: Scripting
> Affects Versions: Scripting HTL Runtime 1.0.0-1.4.0, Scripting HTL Runtime
> 1.1.0-1.4.0, Scripting HTL Runtime 1.1.2-1.4.0
> Reporter: Paul Bjorkstrand
> Assignee: Radu Cotescu
> Priority: Major
>
> Though it is bad practice, it is possible that an object can return null from
> its toString() method. ObjectModel.toBoolean(Object) \[[Line
> 161|https://github.com/apache/sling-org-apache-sling-scripting-sightly-runtime/blob/master/src/main/java/org/apache/sling/scripting/sightly/render/ObjectModel.java#L161]\]
> calls .trim() on a potentially null object.
> This causes a difficult to troubleshoot, deeply nested, and cryptic exception
> to be raised. If object.toString() returns null, then it should be treated
> the same as nearly the rest of HTL, where null is considered "falsey". Doing
> so will save hours of difficult troubleshooting.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)