1

I did not see an anwser anywhere about this specific Sonar violation in the case of an array of an array.

Sonar Violation: Security - Array is stored directly

Code with problem :

public void setData(String[][] data) {  
    if(data == null) { 
        this.data = new String[0][];
    } else { 
        String[][] dataCopy = new String[data.length][];
        System.arraycopy(data, 0, dataCopy, 0, data.length);
        this.data = dataCopy;
    }

I cannot used the following solution because of my java version :

public void setData(String[][] data) {  
    if(data == null) { 
        this.data = new String[0][0];
    } else { 
        this.data = Arrays.copyOf(data, data.length); 
    } 
}

Any suggestions to solve this issue ?

2
  • 6
    See stackoverflow.com/questions/11580948/…
    – igarcia
    Feb 8, 2013 at 16:37
  • 2
    Currently, you're simply copying the original String[] array references into a new String[][]. You need to do a deep copy, i.e. also cloning those inner String[] before placing them into the outer String[][]. Feb 8, 2013 at 16:40

0

Browse other questions tagged or ask your own question.