You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by "Paul Bjorkstrand (JIRA)" <ji...@apache.org> on 2018/11/02 19:09:00 UTC

[jira] [Created] (SLING-8069) Sling Models: Enable constructor injection to use non-public constructors

Paul Bjorkstrand created SLING-8069:
---------------------------------------

             Summary: Sling Models: Enable constructor injection to use non-public constructors
                 Key: SLING-8069
                 URL: https://issues.apache.org/jira/browse/SLING-8069
             Project: Sling
          Issue Type: Improvement
    Affects Versions: Sling Models Impl 1.4.10
            Reporter: Paul Bjorkstrand


In Sling Models, you cannot use a non-public constructor to inject. Looking through the code, there doesn't seem to be any clear reason for this restriction. In my opinion, constructor injection should allow any constructor visibility.

Here are some discussion points:
 * Private fields are allowed for use, so disallowing private constructors seems unnecessary.
 * Private constructors may be bad practice (difficult to test), but Sling should not be telling users how to write their Java code. This is especially true for models, since it should work with POJOs, as stated in the documentation. It would be trivial to add checks to just allow default, protected, or public, but I feel that logic is unnecessary.
 * Non-public methods could also be allowed, but that can be a separate ticket.
 ** A prerequisite of this would be to allow setter injection on models in the first place. Again, not the subject of this ticket.
 * Threading concerns are minimal, but there could be possible deadlocks, as with any multi-threaded application that uses locks. In general, I think locking similar to how it is done in {{InjectableField}} would be sufficient. The risk of deadlock would be similar to the risk of the locking in {{injectableField.set(Object, Result<Object>)}}.

 



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)