Sonar Violation: Security - Array is stored directly

后端 未结 7 2025
广开言路
广开言路 2020-11-27 04:53

There is a Sonar Violation:

Sonar Violation: Security - Array is stored directly

public void setMyArray(String[] myArray) { 
  this.         


        
相关标签:
7条回答
  • 2020-11-27 05:39

    To eliminate them you have to clone the Array before storing / returning it as shown in the following class implementation, so noone can modify or get the original data of your class but only a copy of them.

    public byte[] getarrString() {
        return arrString.clone();
    }
    /**
     * @param arrStringthe arrString to set
     */
    public void arrString(byte[] arrString) {
        this.arrString= arrString.clone();
    }
    

    I used it like this and Now I am not getting any SONAR violation...

    0 讨论(0)
提交回复
热议问题