[
https://issues.apache.org/jira/browse/SLING-11507?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17625766#comment-17625766
]
Robert Munteanu commented on SLING-11507:
-----------------------------------------
What is the tooling entry point that we would have for a build-time failures?
Looking at [the Sling Models
documentation|https://sling.apache.org/documentation/bundles/models.html] it
seems to me all of the processing is done at runtime. There is a potential
exception for adding the {{Sling-Model-Packages}} header to the OSGi bundle,
which can be done manually anyway.
There is a bnd plugin we are using where the check could be added -
https://github.com/apache/sling-org-apache-sling-bnd-models , but that only
applies to projects using bnd and this plug-in.
Another build-time option is an annotation processor, which would trigger a
compilation error when an Sling models annotation is found on a static field.
To my knowledge, it should be invoked automatically by Maven. The only open
question that I have is whether we can detect the {{Sling-Model-Packages}}
header so that we only apply the check to configured classes.
> Field injection should not inject static fields
> -----------------------------------------------
>
> Key: SLING-11507
> URL: https://issues.apache.org/jira/browse/SLING-11507
> Project: Sling
> Issue Type: Task
> Components: Sling Models
> Affects Versions: Models Impl 1.4.14
> Reporter: Joerg Hoh
> Priority: Major
> Fix For: Sling Models Implementation 1.5
>
>
> Currently this injection works:
> {noformat}
> @SlingObject
> private static ResourceResolver resourceResolver;
> {noformat}
> but it should not. Sling Models are Pojos and injection must never inject
> into static fields. Instead it should throw an exception and an error message
> indicating the problem (another option would be to refuse the injection with
> a proper error message).
--
This message was sent by Atlassian Jira
(v8.20.10#820010)