Consider this class
class MyClass {
private MyData[] data;
public MyData[] getData() {
return data == null ? null : (MyData[]) data.clone();
}
This is creating issue
Security - Method returns internal array
Exposing internal arrays directly allows the user to modify some code that could be critical. It is safer to return a copy of the array.
Considering clone
is bad and should be avoided, what can I do to make this code better?