sling-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Justin Edelson (Jira)" <>
Subject [jira] [Commented] (SLING-8079) Returning false in a model PostConstruct causes an java.lang.IllegalStateException
Date Wed, 19 Feb 2020 12:44:00 GMT


Justin Edelson commented on SLING-8079:

[~kwin] What I would suggest is to have {{invokePostConstruct}} return a special (constant)
{{Result}} object (let's say called {{NULL}}) which then the methods which use the {{Result}}
object could check for to determine what to return/throw/log (which yes, would mean {{invokePostConstruct}}
returning a {{Result}} object rather than it being constructed in {{createObject}}). In the
case of {{getAdapter}} this should be logged and {{null}} returned. In the case of {{createModel}},
an exception should be thrown -- there's also some other cases (like adapting an injected
field object). But IMO throwing an exception internally smells like using an exception for
control flow and it would be best to somehow represent this state explicitly.

> Returning false in a model PostConstruct causes an java.lang.IllegalStateException
> ----------------------------------------------------------------------------------
>                 Key: SLING-8079
>                 URL:
>             Project: Sling
>          Issue Type: Bug
>          Components: Sling Models
>    Affects Versions: Sling Models Impl 1.4.6
>            Reporter: Santiago García Pimentel
>            Priority: Major
>             Fix For: Sling Models Impl 1.4.14
> I was just trying the exporter framework and the feature from SLING-7124, where you can
return false in a post construct to prevent a model to being returned.
> Unfortunately I found myself with an IllegalStateException:
> {quote}java.lang.IllegalStateException: No throwable available at
at at
> It seems like the ModelAdapterFactory assumes that there should be an exception if a
model was not returned, which is no longer the case. I don't think this exception should be
> The easiest solution I think is to make o.a.s.models.impl.Result not throw that exception
and let the ModelAdapterFactory handle it, but Im not sure that would the be most appropriate way.

This message was sent by Atlassian Jira

View raw message