hi Felix, On Sat, May 15, 2010 at 12:02 PM, Felix Knecht <[email protected]> wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > We do have mutable objects like Data/Arrays/Collections/... in getter > methods (e.g. [1]). > > - From FindBugs: > "EI: May expose internal representation by returning reference to > mutable object (EI_EXPOSE_REP) > > Returning a reference to a mutable object value stored in one of the > object's fields exposes the internal representation of the object. If > instances are accessed by untrusted code, and unchecked changes to the > mutable object would compromise security or other important properties, > you will need to do something different. Returning a new copy of the > object is better approach in many situations." > > I suggest to clone such data and return the clone instead. > > WDYT?
IMO it depends on the situation, sometimes it makes life hard/impossible to change certain things. Sometimes it is best to return the actual references (assuming that we know what we are doing) Kiran Ayyagari
