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

PostConstruct method may be called multiple times for one instance

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • Sling Models Implementation 1.1.0
    • Sling Models Impl 1.2.0
    • None

    Description

      The problem is in https://github.com/apache/sling/blob/trunk/bundles/extensions/models/impl/src/main/java/org/apache/sling/models/impl/ModelAdapterFactory.java#L732.

      There all @PostConstruct annotated methods are being collected (starting from current class, but including also all super classes). Now you might end up with 2 methods (one in the current and one in the super class).

      The problem appears if those methods have the same signature (i.e. name and parametrization) because then you are not able to call the post construct in the super class (compare with https://blogs.oracle.com/sundararajan/entry/calling_overriden_superclass_method_on).

      Therefore I would propose the following fix:
      Only add post construct methods from superclasses if they have a different signature.

      Attachments

        Activity

          People

            justinedelson Justin Edelson
            kwin Konrad Windszus
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: