Please take our Survey
logo       

Choosing A Webhost:
A web hosting service is a type of Internet hosting service that allows individuals and organizations to provide their own website accessible via the World Wide Web. Web hosts are companies that provide space on a server they own for use by their clients as well as providing Internet connectivity, typically in a data center. Web hosts can also provide data center space and connectivity to the Internet for servers they do not own to be located in their data center, called colocation. more...

Re: Bug in FindBugs?: msg#00013

java.findbugs.general

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?

Yes:

String s[] = SalutationsClass.getSalutations();
s[0] = "Doughhead";

That last line just modified the salutation for everybody that has called or will call getSalutations. Making Salutations final just means nothing else in that class can assign to that variable, it doesn't protect what the variable references. You need to return a copy of the array.

Brian


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
solaris.opensol...    editors.vim/200...    web.turbogears....    jakarta.ant.dev...    mathematics.max...    text.unicode.ge...    lang.ruby.core/...    xfce.announce/2...    network.centeri...    php.cvs.pear/20...    user-groups.lin...    kde.devel.quant...    file-systems.ar...    redhat.fedora.t...    apple.fink.auto...    gnome.orbit.gen...    qplus.devel/200...    culture.transpo...    video.dri.user/...    operators.nanog...   
Home | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe

Navigation