logo       
Google Custom Search
    AddThis Social Bookmark Button
-->

Re: Bug in FindBugs?: msg#00010

Subject: Re: Bug in FindBugs?
Oakes, Jeff (HTSC, IT) wrote:
I ran findBugs against some education example code. The following code was flagged as putting the collection at risk.

*private* *static* *final* String[] /Salutations/ = {

    // These are the valid set of Salutations

    "Mr.", "Master", "Miss", "Mademoiselle", "Madame",

    "Messieure", "Mrs.", "Ms.", "President",

    "Vice President", "Secretary", "Treasurer", "Dr."

};

*public* *static* String[] getSalutations(){

*    return* /Salutations/;

}

Given that the collection is final, and the members are strings (immutable), i do not see where this puts the collection at risk. Have I missed something? Or, is a protective copy of the collection still advisable?

The reference to the array is immutable. The objects referenced by the array are immutable. However, the references contained in the array are not immutable.

    String[] salutations = YourClass.getSalutations();
    salutations[0] = "Ms.";
    System.err.println(YourClass.getSalutations()[0]);

Tom Hawtin


<Prev in Thread] Current Thread [Next in Thread>