You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by "Carsten Ziegeler (Jira)" <ji...@apache.org> on 2022/08/29 08:04:00 UTC

[jira] [Commented] (SLING-11507) Field injection should not inject static fields

    [ https://issues.apache.org/jira/browse/SLING-11507?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17597025#comment-17597025 ] 

Carsten Ziegeler commented on SLING-11507:
------------------------------------------

This is clearly a developer error and should be prevented. The only problem I see is that the check today happens at runtime (unless I'm overlooking something). So if we switch to prevent this, existing bad code might break unexpectedly at runtime. It would be good if we could have a build error instead.

> 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
>
> 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.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)