I m trying to change my codes in my application with using Sonar. How to fix it and why? Thanks.
public class BeanResultSetHandler<T> extends BasicResultSetHandler<T> {
T instance;
Class<T> clas;
Object[] selectFields;
/**
* Constructor
*/
**
public BeanResultSetHandler(Class<T> type, Object[] selectedFields) {
this.clas = type;
this.selectFields = selectedFields;
if (selectedFields == null)
this.selectFields = this.clas.getFields();
}
You have to clone the array before storing it:
this.selectFields = Arrays.copyOf(selectFields, selectedFields.length)Sonar complains because from
BeanResultSetHandlerarray which owner iscallercould be modified.