directory-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Emmanuel Lecharny (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (FC-32) setters that take a list as an argument does not copy it internally
Date Wed, 29 Oct 2014 10:44:33 GMT

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

Emmanuel Lecharny commented on FC-32:
-------------------------------------

Note that the problem is the same for the getters :

{code}
    public List<String> getReqMod()
    {
        return reqMod;
    }
{code}

should ideally return a copy of the internal list :

{code}
    public List<String> getReqMod()
    {
        if ( reqMod != null )
        {
            List<String> result = new ArrayList<String>( reqMod.size() );
            
            System.arraycopy( reqMod, 0, result, 0, reqMod.size() );
   
            return result;

        }
        else
        {
            return null;
        }
    }
{code}


> setters that take a list as an argument does not copy it internally
> -------------------------------------------------------------------
>
>                 Key: FC-32
>                 URL: https://issues.apache.org/jira/browse/FC-32
>             Project: FORTRESS-CORE
>          Issue Type: Bug
>    Affects Versions: 1.0.0-RC39
>            Reporter: Emmanuel Lecharny
>             Fix For: 1.0.0
>
>
> There are many methods like :
> {code}
>     public void setReqMod( List<String> reqMod )
>     {
>         this.reqMod = reqMod;
>     }
> {code}
> Storing the list that is passed is doom to major issues when the original list is modified
outside of the instance, as the stored value will also be modified, even if it was not intended.
> Here, we should copy the list internally :
> {code}
>     public void setReqMod( List<String> reqMod )
>     {
>         if ( reqMod != null )
>         {
>             this.reqMod = new ArrayList<String>( reqMod.size() );
>             
>             System.arraycopy( reqMod, 0, this.reqMod, 0, reqMod.size() );
>         }
>         else
>         {
>             this.reqMod = reqMod;
>         }
>     }
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message