[ 
https://issues.apache.org/jira/browse/SLING-10137?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17283408#comment-17283408
 ] 

René Grob commented on SLING-10137:
-----------------------------------

[~kwin] Sorry, I didn't find that issue. I probably used the wrong keywords in 
my search. And yes you are right {{ModelAdapterFactory.createModel()}} actuall 
throws {{null}} and doesn't return it. SLING-8079 mentions that the exception 
should not be thrown. I would rephrase that to: "An exception indicating that a 
{{@PostConstruct}} method returned {{false}} should be thrown." Because if you 
call createModel() you expect a non-null value back. This guarantee is the 
whole point of using this method. If you want the null-value behavior you could 
just use adaptTo() instead. The current behavior is very confusing. I had to 
debug all the way down to the Sling model implementation to find out why this 
happened.
Should I resolve this issue and mark it as duplicate?

> SlingModelAdapterFactory.createModel() returns null
> ---------------------------------------------------
>
>                 Key: SLING-10137
>                 URL: https://issues.apache.org/jira/browse/SLING-10137
>             Project: Sling
>          Issue Type: Bug
>          Components: Sling Models
>    Affects Versions: Models Implementation 1.4.16
>            Reporter: René Grob
>            Priority: Major
>
> According to the documentation 
> ([https://sling.apache.org/documentation/bundles/models.html#modelfactory-since-120])
>  null checks are not necessary. However if a {{@PostConstruct}} method 
> returns false, 
> {{org.apache.sling.models.impl.ModelAdapterFactory.invokePostConstruct()}} 
> will return {{null}}. This will cause 
> {{org.apache.sling.models.impl.ModelAdapterFactory.createModel()}} to fail 
> because {{result.getThrowable()}} returns {{null}} which will result in 
> {{throw null}}.
> In order to fix this {{internalCreateModel()}} needs to return a valid 
> throwable to indicate that the {{@PostConstruct}} method returned {{false}} 
> and therefore no model was created.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to