You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by "Konrad Windszus (JIRA)" <ji...@apache.org> on 2016/01/08 11:00:47 UTC
[jira] [Comment Edited] (SLING-5389) Sling Models: Do not swallow
PostConstruct exceptions
[ https://issues.apache.org/jira/browse/SLING-5389?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15088986#comment-15088986 ]
Konrad Windszus edited comment on SLING-5389 at 1/8/16 10:00 AM:
-----------------------------------------------------------------
It should be like the following:
* In case {{adaptTo()}} failed (i.e. returns null) expose the failure in the log with level WARN.
* In case injection failed but a default was given or injection was optional, only log with level DEBUG (no matter whether this was due to a PostConstructException or any other exception)
No special handling for {{InvalidModelException}} or {{PostConstructException}} should be done at all.
Fixed with [r1723672|http://svn.apache.org/r1723672] and [r1723673|http://svn.apache.org/r1723673].
was (Author: kwin):
It should be like the following:
* In case {{adaptTo()}} failed (i.e. returns null) expose the failure in the log with level WARN.
* In case injection failed but a default was given, only log with level DEBUG (no matter whether this was due to a PostConstructException or any other exception)
No special handling for {{InvalidModelException}} or {{PostConstructException}} should be done at all.
Fixed with [r1723672|http://svn.apache.org/r1723672].
> 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)