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

Robert Munteanu commented on FELIX-4586:
----------------------------------------

I've tried the new plugin on a component with the following snippet:

{code}
    @Reference(policy = DYNAMIC)
    private StringBuilder bla;
    
    protected synchronized void bindBla(StringBuilder newBla) {
        this.bla = newBla;
    }
    
    protected synchronized void unbindBla(StringBuilder oldBla) {
        if ( this.bla == oldBla ) {
                this.bla = null;
        }
    } 
{code}

I would not expect to get an error, but I do:

{code}[1:1]: @Reference(bla) : Dynamic field should be declared volatile for 
unary references{code}

I would expect this to be triggered only if the methods were generated by the 
plugin, which they were not. Either I misunderstood the feature, or generated 
methods are not properly taken into account.

> A field must be volatile if methods are generated for a dynamic reference
> -------------------------------------------------------------------------
>
>                 Key: FELIX-4586
>                 URL: https://issues.apache.org/jira/browse/FELIX-4586
>             Project: Felix
>          Issue Type: Bug
>          Components: SCR Tooling
>    Affects Versions: maven-scr-plugin 1.17.0, scr ant task 1.11.0, scr 
> generator 1.10.0
>            Reporter: Carsten Ziegeler
>            Assignee: Carsten Ziegeler
>             Fix For: maven-scr-plugin 1.18.0, scr ant task 1.12.0, scr 
> generator 1.11.0
>
>
> If a field is used for a reference, like
> @Reference(policy=DYNAMIC)
> private Field myService
> and methods are generated for this dynamic reference, the field must be 
> declared volatile. Otherwise updates to the field are not visible to the 
> threads calling this component.
> If no methods are generated and the reference is dynamic, a warning should be 
> generated if it is not volatile.



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Reply via email to