You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by "Stefan Seifert (JIRA)" <ji...@apache.org> on 2016/01/23 11:29:39 UTC

[jira] [Closed] (SLING-5389) Sling Models: Do not swallow PostConstruct exceptions

     [ https://issues.apache.org/jira/browse/SLING-5389?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Stefan Seifert closed SLING-5389.
---------------------------------

> Sling Models: Do not swallow PostConstruct exceptions
> -----------------------------------------------------
>
>                 Key: SLING-5389
>                 URL: https://issues.apache.org/jira/browse/SLING-5389
>             Project: Sling
>          Issue Type: Bug
>          Components: Extensions
>    Affects Versions: Sling Models Impl 1.2.4
>            Reporter: Stefan Seifert
>            Assignee: Konrad Windszus
>              Labels: models
>             Fix For: Sling Models Impl 1.2.6
>
>
> SLING-4161 introduced a special handling for postconstruct errors (in ModelAdapterFactory):
> {code:java}
>     public <AdapterType> AdapterType getAdapter(Object adaptable, Class<AdapterType> type) {
>         Result<AdapterType> result = internalCreateModel(adaptable, type);
>         if (!result.wasSuccessfull()) {
>             // treat post-construct and validation exceptions differently, because they are sometimes used for flow-control or validation purposes
>             if (result.getThrowable() instanceof PostConstructException || result.getThrowable() instanceof InvalidModelException) {
>                 log.debug("Could not adapt to model", result.getThrowable());
>             } else {
>                 log.error("Could not adapt to model", result.getThrowable());
>             }
>             return null;
>         } else {
>             return result.getValue();
>         }
>     }
> {code}
> that means that all exceptions that are caught in a {{@PostConstruct}} annotated method are logged only in debug level. even if it's only a NPE in the code.
> this makes identifying errors in PostConstruct methods very hard. we need to come up with a better solution to differentiate between validation errors not to log as errors and real errors like an NPE.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)