[ https://issues.apache.org/jira/browse/SLING-5389?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Stefan Seifert updated SLING-5389: ---------------------------------- Description: 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. was: 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 tmethods 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. > 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 > 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)