Uploaded image for project: 'Sling'
  1. Sling
  2. SLING-5389

Sling Models: Do not swallow PostConstruct exceptions

    XMLWordPrintableJSON

Details

    Description

      SLING-4161 introduced a special handling for postconstruct errors (in ModelAdapterFactory):

          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();
              }
          }
      

      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.

      Attachments

        Issue Links

          Activity

            People

              kwin Konrad Windszus
              sseifert Stefan Seifert
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: