Search
Calendar
novembre 2014
L Ma Me J V S D
« sept    
 12
3456789
10111213141516
17181920212223
24252627282930
Share!
Archives

Articles avec le tag ‘The user-supplied array … is stored directly’

PostHeaderIcon GWT / Sonar / Cannot invoke clone() on the array type… / The user-supplied array … is stored directly

I have to fix all critical « Violations » owing to Sonar.
Let’s consider a basic block:

	public void setSushis(float[] sushis) {
		this.sushis = sushis;
	}

This piece of code raises this error in Sonar:

 Security - Array is stored directly : The user-supplied array 'sushis' is stored directly.

In a naive step, I modified the code as this:

	public void setSushis(float[] sushis) {
		this.sushis = sushis.clone();
	}

This may have been OK… but, now, I get the following error within GWT compilation:

Cannot invoke clone() on the array type float[]

To fix the issue, I amended the code as follows:

	public void setSushis(float[] theSushis) {
        this.sushis= new float[theSushis.length];
        System.arraycopy(theSushis, 0, this.sushis, 0, theSushis.length);
	}

Disclaimer: even though I followed Sonar’s advice and requirements, I am a little skeptic about this kind of « violation ». :-|